Requirements


Functional Requirements:


  • Assign first-fitting spot - On arrival, find the earliest free spot that can fit the vehicle size across floors.
  • Issue ticket on entry - Generate unique ticket with vehicle, spot, and entry time.
  • Compute fee on exit - Calculate duration and apply active PricingStrategy.
  • Lot full handling - If no suitable spot exists, indicate 'Lot Full'.


Core Objects & Relationships

Entities:

  1. Vehicle: Represents a vehicle that uses the system.
  2. Ticket: Represents a ticket that gets issued upon entry.
  3. Pricing: Represents a concrete payment strategy for charging a ticket.
  4. ParkingLot: Represents the physical layout of the system.
  5. ParkingSpot: Represents a spot to be used by a vehicle.
  6. ParkingFloor: Represents a floor on a parking lot.
  7. CheckoutService: Represents the system in charging an amount with a strategy.


Relationships:

  • A ParkingSpot can store at most one Vehicle of the correct size.
  • A Ticket gets issued for one Vehicle and one ParkingSpot.
  • A ParkingLot is composed of several ParkingFloors.
  • A ParkingFloor is composed of several ParkingSpots.
  • A CheckoutSystem charges an amount with a PaymentStrategy.




APIs & Class Members


Interfaces and class methods:

  • PricingStrategy (interface): Defines the contract for objects that can charge an amount.
    • processPayment(amount): charges an amount.


  • Vehicle Class:
    • getSize(): retrieves the size of the vehicle.
  • Ticket Class:
    • computeFee(): computes the fee based on parking duration.
  • ParkingLot:
    • assignParkingSpot(vehicle): assigns a parking spot to a vehicle if it fits and there is enough capacity.
    • getAvailableSpots(): retrieves the number of available spots across the whole parking lot.
  • ParkingFloor:
    • getFirstAvailableSpot(vehicle): retrieves the first available parking spot that suits the bgiven vehicle.
    • getAvailableSpots(): retrieves the number of free spots in this floor.
  • ParkingSpot:
    • isEmpty(): verifies if the parking spot is free or occupied.
    • doesItFit(vehicle): checks if a vehicle fits in the spot.
    • occupy(vehicle): assigns a vehicle to the parking spot.
  • CheckoutService:
    • pay(amount): charges the amount with the class' injected payment strategy.





Deep Dive

  • I want to use lists as containers because of the methods already implemented in the standard libraries.
  • The parkinglot is an independent entity from the parking lot service, so I model the relationship as aggregation. ParkingLotService has a ParkingLot, but their lifespans are independent.