1.3.13 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:

class Team
{
    public string name;

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

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

Inside ShowTeam, the call:

this.DisplayName();

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

this Keeps the Receiver Explicit

Suppose:

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

Then:

team1.ShowTeam();

starts execution in ShowTeam.

Inside that method:

this.DisplayName();

the word:

Activity diagram showing team1.ShowTeam(), then this is team1, then this.DisplayName(), then DisplayName runs on team1.
Team1ShowTeam.

The call stays within the same object.

Compare Same-Object and Other-Object Calls
Same object
this.DisplayName();

The current object receives the call.

Another object
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:

team1 receives ShowTeam and calls its own DisplayName method. Two nested method bars share the same Team lifeline and object state.
ShowTeam calls DisplayName on the same Team object.

The important meaning is:

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:

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:

this.name

belongs to the current Team object, both:

ShowTeam()

and:

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:

this.DisplayName();

read:

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

Same-Object Calls Prepare You for Nested Call Tracing

Consider:

team1.ShowTeam();

which calls:

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.