Archicise
Exercise

Design a Parking Lot System

Apply object-oriented design to model a multi-level parking lot with different vehicle types, payment strategies, and spot allocation.

Functional Requirements

  • Support multiple vehicle types: motorcycles, cars, trucks
  • Multiple spot sizes: small, medium, large
  • Multi-level structure with independent floors
  • Issue and process parking tickets
  • Calculate fees based on duration and vehicle type
  • Track real-time availability

Design Challenges

  • Model spot allocation with the Strategy pattern
  • Apply polymorphism for vehicle type handling
  • Separate pricing concerns from the core domain

Questions to Consider

  • How do you model the relationship between Vehicle, Spot, and Ticket?
  • How do you make the pricing strategy extensible without modifying existing code?
  • How do you enforce that a motorcycle cannot take a large spot when smalls are available?
Your Solution

Class Hierarchy & Polymorphism

Design the Vehicle hierarchy (Vehicle → Motorcycle, Car, Truck) and ParkingSpot hierarchy. Define what attributes and behaviours each class owns. Apply the Open/Closed Principle so new vehicle types can be added without modifying core allocation logic.