2.2.3 Representing Array Fields in UML Class Diagrams

Overview

A class diagram describes a field’s type rather than the values of one instance. If Flight has a seat-number array field, the class shows `int[]`. The brackets belong to the type and tell readers that the field can reference a sequence of integers.

public class Flight
{
    public int[] SeatNumbers;
}
Show an Array Type
Class diagram for representing array fields in uml class diagrams: show an array type.
Show an Array Type
  • New
  • Changed
  • Removed

In UML, write the attribute as `+ SeatNumbers : int[]`. The class diagram does not list seat numbers 12, 14, and 16; those values belong to an individual array in an object diagram. The plus sign means the field is public in this teaching example.

The field’s declaration alone does not create an array. Code must assign an array instance before accessing its elements. Keep the distinction between the class design and the runtime object state.

Trace the Outcome

Compare `SeatNumbers : int[]` with `SeatNumbers : int`. Which description can hold several indexed integers? Then describe where you would show one flight’s actual seat-number values.