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.
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:
- 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 ⏰
The classic marriage example 👰♀️
- 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:
Aggregation
Aggregation
UML also defines aggregation that can be used to indicate that an object is aggregated from different parts.
Notation:
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
- A "owns" B = Composition : B has no meaning or purpose in the system without A
- 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.
Letters | Stands For | Meaning |
---|---|---|
c | Covering | Each object of the superclass belongs to (at least one) subclass |
dc | Disjoint Covering | Each object of the superclass belongs to at least 1 and at most 1 subclass |
d | Disjoint | An object can belong to at most one subclass |
(Empty) | Not Covering and not disjoint | There 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 🍻
Disjoint Covering Example 🎓
Disjoint Example 🔵
Not covering and not disjoint Example 📚
Car Example 🚗