1.7.6 Representing Object Parameter Types in Class Diagrams

Representing Object Parameter Types in Class Diagrams

A game can accept the player whose turn it should record. The class diagram names the accepted type without selecting one particular player.

Read the Code Before Drawing

This is a complete Game definition. Player is an existing class with public integer field NumberOfTurns.

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

Source to translate
public class Game
{
    public void RecordTurn(Player participant)
    {
        participant.NumberOfTurns = participant.NumberOfTurns + 1;
    }
}
Rewrite the Meaning in Ordinary Words
The same design in ordinary words
Define a Game operation named RecordTurn
It accepts one Player input named participant
It updates that player's turn count
It returns no value
This method does not declare a stored Game field for the input

These words describe the class contract, not a sequence of runtime actions. Identify the types, stored members, operation inputs and results, and relationships before choosing compartments and connectors.

Map the Source to Class Boxes and Connectors
Build the Diagram in Violet
  1. Create a class diagram with Game and Player.
  2. In Game's operations enter +RecordTurn(participant : Player) : void. Leave its attributes empty for this source.
  3. In Player's attributes enter +NumberOfTurns : int. This is the field modified through the input reference.
  4. Connect Game toward Player with a dashed dependency labeled parameter type. Do not add a field association named participant.
  5. Save and read the signature without substituting Jordan for the type. Different Player instances can be supplied to the same contract.
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.

Game RecordTurn accepts a Player parameter and returns void; a dashed dependency indicates use, not a stored field.
An object parameter is part of an operation contract
  • New
  • Changed
  • Removed
Read the Contract One Part at a Time

Jordan and Casey can both be supplied on different calls. The class signature stays unchanged because both are Players.

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