1.3.12 Calling Another Method in the Same Object

One Method Can Call Another Method on the Current Object

A class can contain more than one method.

One method may call another method that belongs to the same current object.

For example:

C#
class Team
{
    public string name;

    public void DisplayName()
    {
        System.Console.WriteLine(this.name);
    }

    public void ShowTeam()
    {
        this.DisplayName();
    }
}

Inside ShowTeam, the call:

C#
this.DisplayName();

asks the current Team object to run its own DisplayName method.

this Keeps the Receiver Explicit

Suppose:

C#
Team team1 = new Team();
team1.name = "Wildcats";

Then:

C#
team1.ShowTeam();

starts execution in ShowTeam.

Inside that method:

C#
this.DisplayName();

the word:

Plain text
this

still refers to team1.

Conceptually:

Plain text
team1.ShowTeam()
       ↓
this is team1
       ↓
this.DisplayName()
       ↓
DisplayName runs on team1

The call stays within the same object.

Compare Same-Object and Other-Object Calls

Same object

C#
this.DisplayName();

The current object receives the call.

Another object

C#
this.player.DisplayName();

The code follows a reference to another object, and that other object receives the call.

The final receiver changes the execution context.

A Sequence Diagram Can Show the Interaction

A same-object call can be represented as a message that returns to the same lifeline.

Conceptually:

Plain text
team1 : Team
     |
     | ShowTeam()
     |
     |── DisplayName() ──┐
     |<──────────────────┘

The important meaning is:

While processing one Team method, the same Team object calls another of its methods.

The Second Method Is Still a Separate Method Call

Even though the object remains the same, C# still enters another method.

Execution has a new method frame.

Later debugger tools such as the Call Stack make this visible.

Method Calls Can Build Behavior from Smaller Behaviors

Suppose:

C#
public void ShowTeam()
{
    this.DisplayName();
    this.DisplayScore();
}

ShowTeam coordinates two focused behaviors.

This is useful when each method has a clear responsibility.

Do not turn one method into a random chain of calls merely because calling methods is available.

The calls should support the method's purpose.

The Called Method Can Use the Same Object State

If:

C#
this.name

belongs to the current Team object, both:

C#
ShowTeam()

and:

C#
DisplayName()

can work with that same object's state when their design requires it.

The current object remains the same through the same-object call.

Read the Call as a Responsibility Statement

When you see:

C#
this.DisplayName();

read:

Ask the current object to perform its DisplayName behavior.

This wording keeps the method attached to the object that owns it.

Same-Object Calls Prepare You for Nested Call Tracing

Consider:

C#
team1.ShowTeam();

which calls:

C#
this.DisplayName();

You now have one method call inside another.

That creates a nested execution path.

The next Learning Activity focuses on tracing that path carefully.