1.5.4 Representing Returned Values in Sequence Diagrams

Representing Returned Values in Sequence Diagrams

The Wildcats controller needs the current turn count to decide what to show. A sequence diagram distinguishes the request from the result traveling back.

Read the Code Before Drawing

Inside a Controller method, player1 refers to an existing Player with numberOfTurns equal to 2. Its GetNumberOfTurns() method returns that integer without changing it.

If the underlying C# feature is unfamiliar, use the lesson below while reading this example.

Source to translate
int turns = player1.GetNumberOfTurns();
Rewrite the Meaning in Ordinary Words
Pseudocode for the same behavior
The controller asks player1 for its turn count
player1 reads its current count of 2
The value 2 returns to the waiting controller
The controller stores that result in its local variable turns

Use these words to follow one execution before drawing it. Keep the same order and the same alternatives as the source; simplify the wording without adding work that the code does not perform.

Map the Source to Lifelines and Messages
Build the Diagram in Violet
  1. Create a sequence diagram with controller : Controller and player1 : Player. They exist before the call.
  2. Draw a solid request from controller to player1 labeled GetNumberOfTurns(). Start player1's activation where it receives the request.
  3. Draw a dashed return from player1 back to the controller activation that made the call. Label the result 2 and end the called activation.
  4. Add a note near controller: Store returned value in turns. Keep turns out of the participant headings because it is a caller-local integer.
  5. Save and follow the request outward and result back. Confirm that turns is assigned only after the called operation completes.
Compare the Completed Soccer Diagram

Compare this reference with the diagram you built in Violet. Layout may differ; the source meaning, labels, and relevant connections should agree.

Controller calls GetNumberOfTurns on player1, receives 2, and stores it in local turns.
An integer result returns to the waiting caller
  • New
  • Changed
  • Removed
Trace One Interaction from Top to Bottom

The local variable turns receives 2 only after the call completes. A return carries a value back; it is not a second call made by the player.

Verify the Drawing Against the Source
Predict and Check a Small Change