Diagram Desk

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

Car+plate String+start() voidEngine+displacement intDriver+licenceNo StringCarPark+capacity inthasparksdrives
Class diagram · 9 shapes

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

ShapeSymbolConnections
CarClassholds +plate String, +start() void · → Engine(has) · ← CarPark, Driver
EngineClassholds +displacement int · ← Car
DriverClassholds +licenceNo String · → Car(drives)
CarParkClassholds +capacity int · → Car(parks)

Symbols used here

SymbolMeaning
ClassA box with name, attributes and methods.
CompositionFilled diamond at the whole; parts die with it.
AggregationHollow diamond at the whole; parts can live alone.
AssociationOne class knows and uses another; solid arrow.

All class diagram symbols and how to draw

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

More class diagram examples

All SeewolLabs tools