UML Class Diagrams and Notation

UML Class Diagrams and Notation

The Unified Modeling Language (UML) class diagram provides a standard visual representation of classes and their interrelationships.

The 3 Compartments of a Class Box

A standard UML class box is split into three horizontal sections:

  1. Top: Class Name (italicized if abstract, or prefixed with «interface» if an interface).
  2. Middle: Attributes (e.g. - balance: double).
  3. Bottom: Operations / Methods (e.g. + deposit(amount: double): void).

Visibility Modifiers

| Symbol | Visibility | Description | |---|---|---| | + | Public | Accessible from any class | | - | Private | Accessible only within the declaring class | | # | Protected | Accessible within package and subclasses | | ~ | Package-private | Accessible only within the same package |

Multiplicity Notation

Multiplicity indicates how many instances participate in a relationship:

  • 1: Exactly one
  • 0..1: Zero or one (optional)
  • * or 0..*: Zero or many
  • 1..*: One or more
Exercise 1
Question

In a UML diagram, what does the symbol - preceding an attribute denote?

Show solution ↓
Solution

It denotes private visibility, indicating the member is encapsulated and inaccessible to outside callers.