0.2.13 Representing Object References in Object Diagrams

Representing Object References in Object Diagrams

The Wildcats lineup needs a connection to a particular player, rather than a copied description of that player.

Read the Code Before Drawing

Inside an existing method, Team has text field name and a Player-reference field captain. Player has text field name. The captain assignment stores a path to the existing player.

If the underlying modeling idea is unfamiliar, use the lesson below while reading this example.

Source to translate
Player casey = new Player();
casey.name = "Casey";
Team wildcats = new Team();
wildcats.name = "Wildcats";
wildcats.captain = casey;
Rewrite the Meaning in Ordinary Words
The same snapshot in ordinary words
Create Casey and store Casey as the player name
Create the Wildcats team and store its name
Assign the existing Casey reference to the team captain field
Pause with the team and player connected

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 and place wildcats : Team and casey : Player. Leave enough room between them for a reference line.
  2. Inside wildcats, enter name with value Wildcats and add a field named captain. Leave the captain value area blank: an outgoing reference will identify its target.
  3. Inside casey, enter name with value Casey. Do not duplicate this Player inside the Team box.
  4. Choose Violet's Object reference (from field) tool. Drag from the captain field entry to the casey object, so the line begins at the owning field and points to the target.
  5. Arrange the line so it does not run through either name value. Save and follow the path aloud: wildcats, through captain, reaches casey.
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.

The Wildcats Team instance has a captain reference to the Casey Player instance.
A captain reference points to a specific player
  • New
  • Changed
  • Removed
Trace the Snapshot One Reference or Value at a Time

Follow captain from its owner, wildcats, to its target, casey. The Team stores a reference; the Player box holds Casey's selected state.

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