1.5.4 Representing Returned Values in Sequence Diagrams

A Sequence Diagram Can Show Information Coming Back from a Method Call

You already know that a sequence diagram can show a method call:

caller → team1 : GetScore()

When a method returns a value, the diagram can also show information traveling back toward the caller.

This makes the full interaction visible:

caller
  ↓ method call
team1
  ↑ returned value
caller
The Call and the Return Move in Opposite Directions

Suppose the caller asks:

GetScore()

of team1.

Conceptually:

caller  ── GetScore() ──>  team1
caller  <── score: 3 ───  team1

The first message goes to the object whose method executes.

The returned value goes back to the caller.

Use a Return Message When the Returned Information Matters

For CO-043, the purpose of the diagram is specifically to show returned values.

A return message can communicate that:

GetScore()

produced an integer such as:

3

The method call alone would not show what information came back.

The Sequence Diagram Shows a Runtime Interaction

A class diagram might show:

GetScore() : int

That describes the method generally.

A sequence diagram shows a specific interaction:

controller1 → team1 : GetScore()
team1 → controller1 : 3

The class diagram answers:

The sequence diagram answers:

The Returned Value Should Match the Method's Return Type

If the class diagram says:

GetScore() : int

then a return message showing:

3

makes sense because 3 is an integer.

A return message containing unrelated text would not match the current method contract.

The UML views should agree.

Connect the Diagram to C#

A conceptual sequence interaction:

controller1 → team1 : GetScore()
team1 → controller1 : 3

can correspond to C# such as:

int currentScore = team1.GetScore();

The relationship is:

sequence call
     ↓
C# method invocation
     ↓
method returns int
     ↓
sequence return message
     ↓
local variable receives result
The Caller Can Give the Result a Local Name

In C#:

int currentScore = team1.GetScore();

the local variable is:

currentScore

A sequence diagram is primarily concerned with the interaction between participants.

It may show the returned information clearly without reproducing every local-variable detail from the source.

The exact diagram should communicate the return meaning required by the current task.

Do Not Reverse the Participants

For this call:

controller1 → team1 : GetScore()

team1 is the receiver.

The returned value travels from:

team1

back toward:

controller1

If the return arrow goes in the same direction as the original call, the interaction is being modeled incorrectly.

The Returned Value Is Not a Second Method Call

The return message communicates the result of the original method execution.

It is not another call such as:

ReturnScore()

unless the program actually defines and calls a method with that name.

Do not invent a method merely to represent the return.

Return Messages Occur After the Method Produces the Result

The sequence order is:

GetScore() call
      ↓
GetScore executes
      ↓
value is produced
      ↓
value returns to caller

The return cannot appear before the call that produced it.

Vertical ordering in the sequence diagram should preserve that logic.

Keep the Current Sequence Simple

CO-043 uses simple return flows.

Do not introduce:

  • several conditional return paths;
  • early returns;
  • object-reference returns;
  • returned values passed immediately into another method.

Those ideas belong to later Learning Activities.

Read the Interaction as a Sentence

A complete explanation might be:

If the diagram supports that sentence, it is communicating both the method call and the returned value clearly.

The Main UML Connection

Keep the three views aligned:

Class diagram:
GetScore() : int

Sequence diagram:
caller → team1 : GetScore()
team1 → caller : 3

C#:
int currentScore = team1.GetScore();

Together they show:

  • what the method promises to return;
  • what happened in one interaction;
  • how the returned value is received in code.