2.6.3 Representing Constructor Arguments in Sequence Diagrams

Representing Constructor Arguments in Sequence Diagrams

A sequence diagram records the actual values used to create this Player, rather than the names of every possible constructor input.

Read the Code Before Drawing

Inside a Controller method, Player has the two-parameter constructor from the linked class lesson. It stores name and jerseyNumber in the new instance.

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

Source to translate
Player jordan = new Player("Jordan", 7);
Rewrite the Meaning in Ordinary Words
Pseudocode for the same behavior
The controller begins creating a Player
It supplies the text Jordan and integer 7
A new Player begins its lifetime at that creation request
The constructor initializes the new instance
The completed creation expression supplies its reference to the caller

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 the existing controller : Controller lifeline.
  2. Place the new jordan : Player participant so its heading begins at the creation message, below the existing caller's start.
  3. Draw the creation request from controller to that new participant and label it new Player("Jordan", 7). The actual values travel with this request.
  4. Show the constructor activation. Add a note with Name = "Jordan" and JerseyNumber = 7 to identify the initialized state, then show creation completion returning the new instance reference.
  5. Save and confirm that no part of the Jordan lifeline claims it existed before the request. The local jordan refers to this newly created instance afterward.
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 creates Jordan using name Jordan and jersey 7; the new lifeline starts at creation and the caller receives its reference.
Concrete values supplied during creation
  • New
  • Changed
  • Removed
Trace One Interaction from Top to Bottom

The constructor stores the actual input values. The diagram's completion arrow represents creation expression completion, not a C# return statement written inside the constructor.

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