The parking lot problem looks harmless until vehicle types, spot allocation, tickets, and payments all want an opinion. The goal is to model only the complexity the requirements actually need.

Requirements

  1. Multiple floors and spots
  2. Different vehicle types (bike, car, truck)
  3. Entry/exit gates
  4. Payment system

Core Classes

enum VehicleType {
  BIKE,
  CAR,
  TRUCK
}

class Vehicle {
  licensePlate: string;
  type: VehicleType;
}

class ParkingSpot {
  id: string;
  floor: number;
  type: VehicleType;
  isOccupied: boolean;
  vehicle?: Vehicle;
}

class ParkingLot {
  floors: ParkingFloor[];
  
  findSpot(vehicle: Vehicle): ParkingSpot | null;
  park(vehicle: Vehicle, spot: ParkingSpot): Ticket;
  unpark(ticket: Ticket): Payment;
}

Design Patterns Used

  • Strategy: Different pricing strategies
  • Factory: Creating different spot types
  • Singleton: ParkingLot instance

More details on payment integration coming soon.