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
- Multiple floors and spots
- Different vehicle types (bike, car, truck)
- Entry/exit gates
- 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.