Lessons in this course (8)

2. UML class diagrams and sequence diagrams

Basic★ Must knowLesson 2 of 8

Class diagram notation:

SymbolMeaningExample
+ / - / #public / private / protected+Park(vehicle): Ticket
Solid line + hollow triangleInheritance (is-a)Car ──▷ Vehicle
Dashed line + hollow triangleImplements interfaceUpiPayment ┈┈▷ IPayment
Filled diamondComposition — part can't exist without the wholeFloor ◆── Spot
Hollow diamondAggregation — part can exist independentlyTeam ◇── Player
Plain arrowAssociation / dependencyTicket ──> Spot
1, 0..1, *, 1..*MultiplicityParkingLot 1 ── * Floor
mermaid
classDiagram
    class ParkingLot { +Park(Vehicle) Ticket +Unpark(Ticket) Receipt }
    class Floor { +FindSpot(VehicleType) Spot }
    class Spot { +SpotType Type +bool IsFree +Occupy(Vehicle) +Release() }
    class Vehicle { <<abstract>> +string Number +VehicleType Type }
    ParkingLot "1" *-- "*" Floor
    Floor "1" *-- "*" Spot
    Vehicle <|-- Car
    Vehicle <|-- Bike

Sequence diagram — the order of calls between objects for one use case:

mermaid
sequenceDiagram
    participant G as EntryGate
    participant L as ParkingLot
    participant F as Floor
    participant T as TicketService
    G->>L: Park(car)
    L->>F: FindSpot(Car)
    F-->>L: spot A-12
    L->>T: Issue(car, spot)
    T-->>G: Ticket #881