Skip to main content

Use Case Diagram

Editorial

Purpose of the Use Case Diagram

Before we design classes, we need to answer a fundamental question: who uses this system, and what do they do with it?

The Use Case Diagram is a behavioral UML diagram that answers exactly this. It identifies:

  • Actors — the people or external systems that interact with our Parking Lot
  • Use Cases — the specific actions each actor can perform
  • System Boundary — the rectangle that separates what's inside our system from what's outside

This diagram bridges the gap between requirements (what the system does) and the class diagram (how it's structured). Every use case we identify here will eventually become one or more methods in our classes.

For our Parking Lot, the use case diagram is relatively simple — we have a small number of actors and actions. But drawing it explicitly forces us to think about who initiates each action, which directly influences where methods live in the class diagram.

Identifying Actors

An actor is any entity that interacts with the system from the outside. Actors are NOT classes within the system — they are external entities that trigger behavior.

From our requirements (FR1-FR10), we can identify two primary actors:

1. Driver (Primary Actor)
The person who arrives with a vehicle. The driver interacts with the system to:

  • Park a vehicle (enter the lot, receive a ticket)
  • Unpark a vehicle (return the ticket, pay the fee, leave)
  • Check availability for their vehicle type before entering

The driver doesn't directly choose a spot — the system assigns one. The driver receives a ticket and pays a fee, but the allocation and calculation happen inside the system.

2. Parking Lot Admin (Primary Actor)
The administrator who manages the lot's configuration. The admin interacts with the system to:

  • Add or configure floors and spots
  • Set or change the pricing strategy
  • View capacity and availability reports

In a real system, there might also be a Payment System as an external actor (processing card payments), but payment integration is out of our scope (as defined in the Requirements tutorial).

Why only two actors?
Because this is an Easy-level problem with a focused scope. Medium and Hard problems will have more actors — the Hotel Management System (DP14) has a Guest, a Receptionist and an Admin; the Online Shopping System (DP20) has a Buyer, a Seller and the System itself.

Identifying Use Cases

Each use case represents a discrete action that an actor performs. We derive them directly from our functional requirements:

Driver Use Cases:

Use CaseDerived FromDescription
Park VehicleFR5, FR8Driver arrives → system finds an available compatible spot → assigns spot → generates ticket
Unpark VehicleFR6, FR9Driver presents ticket → system calculates fee → releases spot → returns fee amount
Check AvailabilityFR10Driver queries whether spots are available for their vehicle type before entering

Admin Use Cases:

Use CaseDerived FromDescription
Add FloorFR1Admin configures a new floor with a set number of spots
Set Pricing StrategyFR7Admin switches between pricing models (hourly, flat-rate)
View CapacityFR10Admin checks how many spots of each type are available per floor

Relationships between use cases:

  • Park Vehicle includes Find Available Spot — parking always requires finding a spot first. This is an <<include>> relationship.
  • Park Vehicle includes Generate Ticket — a ticket is always generated when a vehicle is parked.
  • Unpark Vehicle includes Calculate Fee — a fee is always calculated on exit.

Run the Use Case Diagram

The system boundary rectangle contains all use cases. Actors stand outside the boundary, connected by lines to the use cases they initiate. The diagram below is live: set up the lot as the Admin, then park and pay as the Driver — each use case lights up when its actor runs it, and every «include» fires every time. Find Available Spot, Generate Ticket and Calculate Fee have no actor of their own: they run only inside Park Vehicle and Unpark Vehicle.

Interactive: the Parking Lot use case diagram runs live. As the Admin, add the usage example's two floors, switch between HourlyPricing ($5.00 per hour) and FlatRatePricing ($20.00 flat) and view each floor's capacity; as the Driver, check availability for your vehicle type, park the usage example's car, motorcycle and truck, move the clock and unpark with the ticket. Park Vehicle always includes Find Available Spot and Generate Ticket, and stops with the code's error when no compatible spot is free; Unpark Vehicle always includes Calculate Fee and refuses a ticket that was already used.

Complete Use Case Diagram

A UML use case diagram of the Parking Lot System. Two actors stand outside the system boundary: the Driver on the left, who parks a vehicle, and the Admin on the right, who manages the lot. The Driver is associated with Park Vehicle, Unpark Vehicle and Check Availability; the Admin with Add Floor, Set Pricing Strategy and View Capacity. Three included use cases have no actor: Find Available Spot, Generate Ticket and Calculate Fee. Dashed «include» arrows run from Park Vehicle to Find Available Spot and to Generate Ticket, and from Unpark Vehicle to Calculate Fee. A legend gives the notation: a solid line is an association, and an «include» arrow points from the base use case to the included one.

From Use Cases to Methods

The use case diagram isn't just a pretty picture — it directly informs where methods live in our class design:

Use CaseWill BecomeIn Class
Park VehicleparkVehicle(vehicle)ParkingLot
Unpark VehicleunparkVehicle(ticketId)ParkingLot
Find Available SpotfindAvailableSpot(vehicleType)Floor
Generate TicketConstructor / factory methodParkingTicket
Calculate FeecalculateFee(duration)PricingStrategy
Check AvailabilitygetAvailableSpots(vehicleType)ParkingLot
Set Pricing StrategysetPricingStrategy(strategy)ParkingLot
Add FlooraddFloor(floor)ParkingLot
View CapacitygetAvailableSpotCount(spotType)Floor

Notice how the Driver's use cases map to the ParkingLot class (it's the entry point), while the included use cases map to internal classes (Floor, ParkingTicket, PricingStrategy). This is the beginning of responsibility assignment — the ParkingLot coordinates, but it delegates specific tasks to specialized classes.

This pattern — a coordinator that delegates to helpers — is a sign of healthy design. It keeps each class focused (SRP from Fundamentals S6) and makes the system extensible (OCP from Fundamentals S6).

In the next tutorial, we'll take these method assignments and build the complete class diagram.