Car composition and aggregation class diagram
Car and engine are composition, car and driver association, car park and car aggregation. The diamond always sits at the whole.
The diagram
Reading it step by step
- 'Car' (class): 1 attributes, 1 methods.
- 'Engine' (class): 1 attributes, 0 methods.
- 'Driver' (class): 1 attributes, 0 methods.
- 'CarPark' (class): 1 attributes, 0 methods.
- 'Car' is composed of 'Engine' (has).
- 'CarPark' aggregates 'Car' (parks).
- 'Driver' is associated with 'Car' (drives).
Shape by shape
| Shape | Symbol | Connections |
|---|---|---|
| Car | Class | holds +plate String, +start() void · → Engine(has) · ← CarPark, Driver |
| Engine | Class | holds +displacement int · ← Car |
| Driver | Class | holds +licenceNo String · → Car(drives) |
| CarPark | Class | holds +capacity int · → Car(parks) |
Symbols used here
| Symbol | Meaning |
|---|---|
| Class | A box with name, attributes and methods. |
| Composition | Filled diamond at the whole; parts die with it. |
| Aggregation | Hollow diamond at the whole; parts can live alone. |
| Association | One class knows and uses another; solid arrow. |
Diagram text
Paste this text into the editor to get the same picture, then change the names to fit your own work.
# Car composition and aggregation class diagram
classDiagram
class Car {
+plate String
+start() void
}
class Engine {
+displacement int
}
class Driver {
+licenceNo String
}
class CarPark {
+capacity int
}
Car *-- Engine : has
CarPark o-- Car : parks
Driver --> Car : drives