A UML sequence diagram shows:
That makes it a useful guide for C# method-call structure.
Consider this conceptual interaction:
The message says:
The receiving object needs a class that defines the requested method. For this example, Team has one method:
class Team
{
public void DisplayName()
{
System.Console.WriteLine("Wildcats");
}
}The message identifies team1 as the receiving object and DisplayName() as the method to run.
Now consider a nested interaction:
Read the messages from top to bottom. First, controller1 calls ShowTeamName() on player1. While that method is running, player1 calls DisplayName() on team1.
The calling code creates the objects, connects the Player to the Team, and starts the first call:
Team team1 = new Team();
Player player1 = new Player();
player1.team = team1;
player1.ShowTeamName();That call enters the Player method below. Its team field refers to the same team1 object:
class Player
{
public Team team;
public void ShowTeamName()
{
this.team.DisplayName();
}
}Inside ShowTeamName(), this.team.DisplayName(); starts the second call in the diagram. It runs the Team method shown earlier, which displays Wildcats.
The controller starts the interaction; the Player method contains the nested call to the Team.
A message names a method that belongs to the receiving object's class:
Here, team1 is a Team object, and the Team class defines DisplayName(). The Player reaches that same object through its team field.
The diagram and code describe the same interaction: the receiver determines which object acts, and the message names its method.
The goal is not line-for-line conversion of drawing geometry.
The goal is to preserve:
That is the common meaning shared by the UML sequence diagram and the C# source.