Skip to content

Class Diagrams

See the UML class diagram syntax summarized here.

New Class Diagram Extensions

N-ary associations

N-ary associations

A n-ary association indicates that three (or more) objects are associated with each other.

The association is meaningless if one of the objects is missing.

uml diagram

How to understand the multiplicity of Class3: If two objects which are instantiations of classes 1 and 2 are associated with each other, the pair of these objects is a associated with i..k objects of class 3.

Examples:

uml diagram
  • If a room has been allocated for a given time slot, then it is for exactly one course.
  • If a given course has been scheduled for a given time slot one or more rooms have been allocated
  • If a given course is associated with a given room, one or more time slots have been allocated for this course for this room.

Example with association class ⏰

uml diagram

The classic marriage example 👰‍♀️

uml diagram
  • One man can be married to one woman.
  • The Same Objects of Man and woman cannot remarry.

Composition

Composition

Officially called "composite aggregation". A composed object is an object made out of one or more other objects.

Properties:

  • An object that takes part in a composition is associated with a single composed object(cannot be part of two objects)
  • If the composed object is deleted, its parts also are deleted.

Notation:

uml diagram

Aggregation

Aggregation

UML also defines aggregation that can be used to indicate that an object is aggregated from different parts.

Notation:

uml diagram

Composition and Aggregation both indicate that an object is made out of multiple parts. But in an aggregation implies that the parts can exist independently of the Composite object.

In the bicycle example 🚴 the frame of the bicycle cannot exist without the bicycle. But the wheels can be removed and swapped to another bike.

in short

  1. A "owns" B = Composition : B has no meaning or purpose in the system without A
  2. A "uses" B = Aggregation : B exists independently (conceptually) from A

Extended Generalization

This notation only applies when a superclass has more than one subclass. Thanks to this notation we can model how objects occur in the system.

LettersStands ForMeaning
cCoveringEach object of the superclass belongs to (at least one) subclass
dcDisjoint CoveringEach object of the superclass belongs to at least 1 and at most 1 subclass
dDisjointAn object can belong to at most one subclass
(Empty)Not Covering and not disjointThere can be objects that do not belong to any subclass and there can be objects that belong to different subclasses at the same time

Covering Example 🍻

uml diagram

Disjoint Covering Example 🎓

uml diagram

Disjoint Example 🔵

uml diagram

Not covering and not disjoint Example 📚

uml diagram

Car Example 🚗

uml diagram