devnotes.

Reading UML Class Diagrams

UML (Unified Modeling Language) is a standardized visual notation for describing the structure and design of object-oriented systems. Class diagrams are the most commonly used UML diagram type — a visual map of a system's classes, their properties and methods, and the relationships between them, useful for planning a design before writing code, and for communicating architecture to a team.

A single class box is divided into three sections:

+---------------------------+
|          Employee         |  <- class name
+---------------------------+
| - name: string             |  <- properties (with visibility)
| - salary: float             |
| # employeeId: int            |
+---------------------------+
| + getName(): string          |  <- methods (with visibility)
| + calculatePay(): float       |
| - validateId(): bool           |
+---------------------------+

Visibility symbols (matching the access modifiers chapter):

  • + public
  • - private
  • # protected

Relationship notation between classes:

  • Association (plain line) — classes that know about and use each other: Teacher — Student
  • Inheritance / generalization (line with a hollow triangle arrowhead, pointing to the parent) — Dog —▷ Animal
  • Implementation (dashed line with a hollow triangle, pointing to the interface) — Circle ┄▷ Shape
  • Aggregation (line with a hollow diamond at the 'whole' end) — a 'has-a' relationship where the parts can exist independently of the whole: Department ◇— Professor (a professor can exist without belonging to any specific department)
  • Composition (line with a filled diamond at the 'whole' end) — a stronger 'has-a' where the parts cannot exist without the whole: House ◆— Room (a room stops existing if the house is destroyed)
  • Dependency (dashed line with an open arrowhead) — one class temporarily uses another, often just as a method parameter, without holding a lasting reference

Multiplicities (like 1, 0..1, *, 1..*) are written near the ends of relationship lines to indicate how many instances of one class relate to how many of another — for example, Department 1 ◇— * Professor shows one department can have many professors.

How to Read UML Class Diagrams | DevNotes