Activity Diagram
Purpose of the Activity Diagram
The Class Diagram shows us what the system is made of. The Activity Diagram shows us how it behaves — the step-by-step workflow from a vehicle arriving at the entrance to leaving with a calculated fee.
Activity Diagrams are behavioral UML diagrams (covered in Fundamentals S5) that model workflows and decision points. They're especially useful for two things:
- Visualizing branching logic — what happens if no spot is available? What happens if the vehicle type doesn't match any spot?
- Verifying completeness — by tracing every path through the diagram, we can confirm our class design handles all scenarios
For the Parking Lot, we'll model two key workflows:
- Park Vehicle — the happy path and the rejection path
- Unpark Vehicle — ticket lookup, fee calculation, spot release
These workflows directly map to the parkVehicle() and unparkVehicle() methods in our ParkingLot class. The activity diagram helps us verify that our method design is complete before we write code.
Activity Diagram Elements
Before building our diagrams, let's review the key notation elements we'll use:
- Initial Node (filled black circle) — where the workflow starts
- Activity/Action (rounded rectangle) — a step in the workflow
- Decision Node (diamond ◇) — a branching point with conditions on outgoing arrows
- Merge Node (diamond ◇) — where branches come back together
- Final Node (filled black circle inside a circle) — where the workflow ends
- Flow Arrows — directed edges connecting activities, with guard conditions in
[brackets]on decision branches
We covered these in detail in Fundamentals S5 (Activity Diagrams — Workflow and Decision Points). Here, we apply them to a real system.
Workflow 1: Park Vehicle
The Park Vehicle workflow begins when a driver arrives and ends with either a successful parking (ticket issued) or a rejection (lot full for that vehicle type).
Step-by-step trace:
- Vehicle Arrives — Driver enters with a vehicle (Car, Truck, or Motorcycle)
- Get Vehicle Type — System reads the vehicle type to determine spot compatibility
- Search Floors for Available Spot — System iterates through floors, calling
floor.findAvailableSpot(vehicleType)on each - Decision: Spot Found?
- [Yes] → Proceed to park
- [No] → Reject the vehicle (lot full for this type)
- Park Vehicle in Spot — Call
spot.park(vehicle)to mark the spot as occupied - Generate Parking Ticket — Create a
ParkingTicketwith vehicle, spot, and current timestamp - Return Ticket to Driver — The driver receives the ticket
Key design insight: The decision at step 4 is critical. Notice that "lot full" is type-specific — there might be large spots available, but if the vehicle is a truck and all large spots are taken, the truck is rejected even though compact spots exist. This nuance is what makes the canFitVehicle(VehicleType) method on ParkingSpot essential.
Park Vehicle — Activity Diagram

Workflow 2: Unpark Vehicle
The Unpark Vehicle workflow begins when a driver presents their ticket and ends with the fee being returned and the spot released.
Step-by-step trace:
- Driver Presents Ticket — Driver provides the ticket ID
- Lookup Ticket — System retrieves the
ParkingTicketfromactiveTicketsmap - Decision: Ticket Valid?
- [No] → Return error (invalid ticket ID)
- [Yes] → Proceed to unpark
- Remove Ticket — Remove the ticket from the
activeTicketsmap - Record Exit Time — System captures the current timestamp
- Calculate Duration — Compute time difference:
exitTime - entryTime - Calculate Fee — Call
calculateFee(duration)on the activepricingStrategy - Release Spot — Call
spot.unpark()to mark the spot as available - Return Fee to Driver — Display the calculated parking fee
Key design insight: Notice that the pricing strategy is invoked at step 7 — this is where the Strategy Pattern pays off. Whether the lot uses hourly pricing, flat-rate pricing, or any future pricing model, this step always calls the same calculateFee() method. The ParkingLot never knows which algorithm runs. This is polymorphism in action (Fundamentals S3).
Unpark Vehicle — Activity Diagram

From Activity Diagrams to Code
Activity diagrams translate almost directly to method implementations. Each activity becomes a line of code, each decision becomes an if statement, and the flow order becomes the sequential execution order.
Here's how the Park Vehicle diagram maps to our ParkingLot.parkVehicle() method:
| Activity | Code |
|---|---|
| Get Vehicle Type | vehicleType = vehicle.getType() |
| Search Floors | for floor in self.floors: |
| Find Available Spot | spot = floor.findAvailableSpot(vehicleType) |
| Decision: Spot Found? | if spot is not None: |
| [No] Lot Full | raise ValueError(...) |
| Park Vehicle | spot.park(vehicle) |
| Generate Ticket | ticket = ParkingTicket(vehicle, spot) |
| Return Ticket | return ticket |
This direct mapping is why activity diagrams are valuable — they serve as pseudocode for your methods. In the Code Implementation tutorial, you'll see these exact steps translated into Python and Java.
The activity diagrams also reveal edge cases we'll address in the Testing tutorial:
- What if two vehicles try to park in the last spot simultaneously?
- What if a driver presents someone else's ticket?
- What if the pricing strategy is null (not set)?