2.7.3 Representing Property Access in Sequence Diagrams

Representing Property Access in Sequence Diagrams

A property write invokes its setter and a read invokes its getter. A sequence diagram can make that execution visible even though the caller uses assignment syntax.

Follow the write before the read

Assume an existing Player whose JerseyNumber property stores any assigned integer and returns that stored value. The backing field initially contains 1. The complete implementation appears in the accessor lesson.

Statements in a controller method
selected.JerseyNumber = 7;
int displayedNumber = selected.JerseyNumber;

The setter first stores 7. Once it completes, the getter returns 7 and the controller assigns that result to displayedNumber. No object is created by either statement.

Represent the accessor interactions
  1. Create controller : Controller and selected : Player lifelines in Violet.
  2. Send set JerseyNumber(7) to selected and show its activation finishing.
  3. Below it, send get JerseyNumber() to the same receiver. Show the returned value 7.
  4. Add a controller note Store result in displayedNumber.
  5. Explain that these message labels describe accessors; they are not C# method names students should type.
Controller writes jersey number 7 through the setter, then reads 7 through the getter on the same Player.
A setter stores before a getter reads
Check the member declaration

Setter completion returns control, not an integer result. The getter result is the value stored by the caller.

Apply the idea
Check your understanding