3.4.11 Representing Inheritance in Object Diagrams

Representing Inheritance in Object Diagrams

A Goalkeeper instance contains inherited Player state and its own specialized state. An object snapshot represents one runtime instance, not one instance per level of the hierarchy.

Read the Code Before Drawing

Player defines public fields Name and NumberOfTurns. Goalkeeper inherits Player and adds public integer field SavesPracticed. Its parameterless creation is valid in this teaching model.

Source to translate
Goalkeeper casey = new Goalkeeper();
casey.Name = "Casey";
casey.NumberOfTurns = 2;
casey.SavesPracticed = 3;
Player selected = casey;
Rewrite the Meaning in Ordinary Words
The same snapshot in ordinary words
Create one Goalkeeper named Casey
Assign the inherited Name and NumberOfTurns fields
Assign the specialized SavesPracticed field
Make selected, declared as Player, refer to that same Goalkeeper
Pause with one runtime instance and two reference names

These words fix the snapshot moment and separate instances, values, and reference targets. Follow the source to that pause before deciding how many boxes to draw and which current values belong inside them.

Map the Source to Object Boxes and References
Build the Diagram in Violet
  1. Create an object diagram in Violet with one underlined header casey : Goalkeeper.
  2. Add inherited fields Name with value Casey and NumberOfTurns with value 2.
  3. Add the derived field SavesPracticed with value 3. Keep all three rows in this same object.
  4. Add a note selected is declared Player and refers to this same instance. It explains the local reference without creating another object box.
  5. Save and check that the snapshot has one Goalkeeper instance. A second reference name and an inherited class do not each add another object.
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.

Casey is one Goalkeeper with inherited Name and NumberOfTurns plus SavesPracticed. The Player reference selected targets the same instance.
One derived instance includes inherited state
  • New
  • Changed
  • Removed
Trace the Snapshot One Reference or Value at a Time

Changing selected.NumberOfTurns would change the value shown in this one box. It would not change an imagined separate Player box.

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