1.7.9 Object Returns in Sequence Diagrams

A Sequence Can Show a Returned Reference

A return message carries the method's result back to the caller. When the result is an object reference, its label can identify the object returned.

Game returns its existing Player reference to Controller.
Object reference in a sequence diagram
  • New
  • Changed
  • Removed
The Call Goes to the Receiver

For `Player selected = game1.GetCurrentPlayer();`, the call message travels from the caller to `game1 : Game` and is labeled `GetCurrentPlayer()`.

The Return Identifies the Player

If Game's `CurrentPlayer` field refers to `player1 : Player`, the return message goes from Game back to its caller. A label such as `player1 : Player` identifies the value returned. The Player object does not become the receiver of `GetCurrentPlayer()`.

Game creates a new Player and returns its reference to Controller.
A second interaction
  • New
  • Changed
  • Removed
Returning Does Not Automatically Create

When Game returns its existing `CurrentPlayer`, the caller gets another reference to the same Player. A return arrow does not imply a new Player object.

Creation Would Appear Earlier

If Game executes `new Player()` before returning, the interaction includes creation of that Player and then the return of its reference. The object has an origin before the returned value reaches the caller.