1.2.6 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:

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

Each row names one field and identifies its type.

Read UML Field Notation

A common form is:

Plain text
fieldName : Type

For:

Plain text
jerseyNumber : int

read:

Player has a field named jerseyNumber whose type is int.

For:

Plain text
isAvailable : bool

read:

Player has a Boolean field named isAvailable.

Class Fields Do Not Show One Object's Current Value

Class diagram:

Plain text
name : string

Object diagram:

Plain text
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:

Plain text
team : Team

This field is different from:

Plain text
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:

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

The types reflect the intended information:

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.