UML & Modeling • Sequence DiagramsMedium⏱️ ~3 min
Applying Sequence Diagrams: Parking Lot Entry Flow
Scenario: Vehicle Entry to Parking Lot
Let's model the complete interaction when a vehicle requests entry to a parking lot. This demonstrates how sequence diagrams capture object collaboration.
Parking Lot Entry Sequence
:Driver → :EntryTerminal: pressButton()
:EntryTerminal → :ParkingLot: requestSpot(vehicleType)
:ParkingLot → :SpotManager: findAvailableSpot(COMPACT)
:SpotManager → :ParkingSpot: isAvailable()
:ParkingSpot ⤶ :SpotManager: true
:SpotManager ⤶ :ParkingLot: spot:ParkingSpot
:ParkingLot → :Ticket: «create»(spot, entryTime)
:ParkingLot → :ParkingSpot: markOccupied()
:ParkingLot ⤶ :EntryTerminal: ticket:Ticket
:EntryTerminal → :Gate: open()
:EntryTerminal ⤶ :Driver: dispenseTicket(ticket)
Class Participants Involved
EntryTerminal
+ pressButton()
+ dispenseTicket()
+ dispenseTicket()
ParkingLot
+ requestSpot(type)
+ releaseSpot(ticket)
+ releaseSpot(ticket)
SpotManager
+ findAvailableSpot()
+ getAllSpots()
+ getAllSpots()
Ticket
- entryTime
- spot
- spot
Key Observations
- First,
EntryTerminalacts as facade, coordinating the entire workflow - Second,
ParkingLotdelegates spot finding toSpotManager(Single Responsibility Principle) - Third,
Ticketis created only after confirming spot availability - Fourth, spot state changes (
markOccupied) happen before gate opens (consistency)
Interview Tip: Always validate preconditions before state changes. In this flow, we check
isAvailable() before creating the ticket. If no spots exist, the sequence would show an alternative path returning an error to the driver.Handling Exceptions
If no spots are available, the sequence changes: SpotManager returns null, ParkingLot returns error to EntryTerminal, terminal displays "Lot Full" message, and gate remains closed. Always show both happy path and at least one error path in interviews.
💡 Key Takeaways
✓Sequence diagrams validate that class design supports required workflows
✓Shows delegation pattern: EntryTerminal coordinates, SpotManager finds spots
✓Object creation happens mid-flow when Ticket is instantiated
✓State changes (markOccupied) occur before irreversible actions (gate opens)
✓Error paths should be considered even if not drawn in detail
📌 Examples
1Parking entry: Driver presses button, system finds spot, creates ticket, opens gate
2Library checkout: User scans card, system validates, reserves book, updates inventory
3Elevator request: User presses floor button, controller assigns elevator, elevator moves