1.6.3 Representing Shared References in Object Diagrams

Representing Shared References in Object Diagrams

Two paths can reach one Wildcats player. The snapshot must show sharing rather than inventing a copy for every field.

Read the Code Before Drawing

Inside an existing method, jordan refers to one Player with numberOfTurns initially 0. Team has Player field captain; Game has Player field currentPlayer. wildcats and practice are existing instances.

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

Source to translate
wildcats.captain = jordan;
practice.currentPlayer = jordan;
wildcats.captain.numberOfTurns = 1;
Rewrite the Meaning in Ordinary Words
The same snapshot in ordinary words
Make the team captain refer to Jordan
Make the game currentPlayer refer to the same Jordan
Use the captain path to set Jordan's turn count to 1
Pause with two paths to that one updated Player

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 with wildcats : Team, practice : Game, and one jordan : Player.
  2. Add reference field captain inside wildcats and currentPlayer inside practice. Leave their value areas blank.
  3. Inside jordan add numberOfTurns with current value 1. The update through wildcats.captain has executed.
  4. Use Object reference (from field) to connect captain to jordan, then currentPlayer to that same jordan box. Keep two separate lines with a single common target.
  5. Save and follow both paths. The drawing should contain three objects and two reference paths, not two copies of Jordan.
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.

Team captain and Game currentPlayer both target Jordan, whose turn count is one after the update.
Two field references, one player identity
  • New
  • Changed
  • Removed
Trace the Snapshot One Reference or Value at a Time

Follow each path to its endpoint. Both end at the same box; there is one current turn count, not one count per incoming arrow.

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