1.2.3 Fields in UML Class Diagrams

Fields Describe Information Objects of a Class Can Hold

A class diagram can list fields beneath the class name.

For example:

Player
--------------------------------
name : string
jerseyNumber : int
isAvailable : bool

Each row names one field and identifies its type.

Read UML Field Notation

A common form is:

fieldName : Type

For:

jerseyNumber : int

read:

For:

isAvailable : bool

read:

Class Fields Do Not Show One Object's Current Value

Class diagram:

name : string

Object diagram:

name = "Jordan"

The class definition tells you what information Player objects can contain.

The object snapshot tells you the current value for one instance.

A Field Can Use Another Custom Class Type

If a Player can refer to a Team:

team : Team

This field is different from:

teamName : string

The first can hold a Team object reference.

The second holds text.

That distinction helps represent object relationships directly.

Field Types Should Match the Information

A conceptual soccer class could be:

Player
--------------------------------
name : string
jerseyNumber : int
isAvailable : bool
team : Team

The types reflect the intended information:

  • text;
  • whole number;
  • Boolean;
  • object reference.
The Diagram Should Be Traceable to the Requirement

Do not add fields simply because a real Player could have them.

Include the fields needed by the current software design.

Each field should have a clear purpose in the model.