3.4.12 Representing Virtual and Overridden Methods in Sequence Diagrams

Representing Virtual and Overridden Methods in Sequence Diagrams

A variable typed Player can refer to a Goalkeeper instance. A virtual call chooses the override belonging to the actual runtime object.

Read the Code Before Drawing

Inside a Controller method, casey refers to a Goalkeeper with both counts initially zero. Player.RecordTurn is virtual; Goalkeeper overrides it, calls base.RecordTurn, then increments SavesPracticed.

Source to translate
Player selected = casey;
selected.RecordTurn();
Rewrite the Meaning in Ordinary Words
Pseudocode for the same behavior
Make a Player-typed selected reference point to Casey the Goalkeeper
Call RecordTurn through selected
Use the runtime Goalkeeper override
Run its explicit base body, then its specialized update
Finish on the same Goalkeeper instance

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 lifelines controller : Controller and casey : Goalkeeper. Keep only one receiver object.
  2. Draw the solid request RecordTurn() from controller to casey and start its activation.
  3. Attach a note explaining selected has declared type Player; runtime dispatch selects Goalkeeper.RecordTurn.
  4. Continue the note with the actual work: the explicit base body increments NumberOfTurns, then the override increments SavesPracticed. End the activation and show the void completion.
  5. Save and identify the same receiver across reference assignment, dispatch, base work, and override work. None of those stages creates a base-class copy.
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.

A Player-typed reference to Casey calls Goalkeeper RecordTurn; the same Goalkeeper object executes base and derived work.
Runtime type selects the override
  • New
  • Changed
  • Removed
Trace One Interaction from Top to Bottom

After completion, NumberOfTurns and SavesPracticed are both 1. A plain Player receiver would execute only the Player body and would not have a SavesPracticed field.

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