0.4.10 Representing Attributes and Data Types in Class Diagrams

Representing Attributes and Data Types in Class Diagrams

The Wildcats software needs to say what information every Player can hold before anyone's particular values are entered.

Read the Requirements Before Drawing

This is a design requirement written in ordinary words. A text value maps to string, a whole-number value to int, a decimal measurement here to double, and availability to bool.

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

Requirements to translate
Each Player has a name as text.
Each Player has a jersey number as a whole number.
Each Player has a height in meters as a decimal measurement.
Each Player has an availability value that is true or false.
Rewrite the Meaning in Ordinary Words
The same design in ordinary words
Define the information supported by every Player
A name holds text
A jersey number holds a whole number
A height in meters holds a decimal measurement
Availability holds true or false
Describe types rather than one player's current values

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 in Violet and place one class node headed Player. Use the class-name area, not an object-instance header with a colon.
  2. In the attributes compartment, enter name : string and jerseyNumber : int on separate lines. Preserve each name and the name-before-type order.
  3. Add heightMeters : double and isAvailable : bool on their own attribute lines. Keep the operations compartment empty because the requirement defines no behavior.
  4. Do not add current values such as Jordan, 7, or true. This is a structure view that must apply to different Player instances.
  5. Save the diagram and read all four entries as contracts: a Player can hold this information with this type.
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.

Player defines text name, integer jersey number, decimal height, and Boolean availability; no instance values are shown.
One player design with four attribute types
  • New
  • Changed
  • Removed
Read the Contract One Part at a Time

The same class supports Jordan with jersey 7 and Casey with jersey 1. Neither value has to be written into the class diagram.

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