Parking Lot System

Design a parking lot management system — a classic LLD interview question covering OOP, design patterns, and concurrency.

4 min read2026-03-22mediumlldparking-lotoopinterview

Requirements

Functional

  1. Multiple floors, each with parking spots of different sizes
  2. Support vehicle types: Motorcycle, Car, Bus
  3. Assign nearest available spot matching vehicle size
  4. Track entry/exit, calculate parking fee
  5. Display available spots per floor/type

Non-Functional

  • Thread-safe (concurrent entry/exit)
  • Extensible (new vehicle types, payment methods)

Interview Approach

Start by clarifying requirements, then identify core entities, define relationships, and finally discuss concurrency and extensibility.

Class Diagram

Core Entities

ParkingLot (Singleton)
ā”œā”€ā”€ Floor[]
│   ā”œā”€ā”€ ParkingSpot[]
│   │   ā”œā”€ā”€ SmallSpot
│   │   ā”œā”€ā”€ MediumSpot
│   │   └── LargeSpot
ā”œā”€ā”€ EntryPanel[]
ā”œā”€ā”€ ExitPanel[]
ā”œā”€ā”€ DisplayBoard[]
└── ParkingTicket[]

Vehicle (Abstract)
ā”œā”€ā”€ Motorcycle
ā”œā”€ā”€ Car
└── Bus

Implementation

Design Patterns Used

PatternWhere
SingletonParkingLot — only one instance
StrategyFee calculation — different strategies for hourly, daily, monthly
ObserverDisplayBoard — updates when spot availability changes
FactoryVehicle creation based on type

Fee Calculation (Strategy Pattern)

interface PricingStrategy {
  calculate(hours: number): number;
}

class HourlyPricing implements PricingStrategy {
  calculate(hours: number): number {
    return Math.ceil(hours) * 5; // $5/hour
  }
}

class DailyPricing implements PricingStrategy {
  calculate(hours: number): number {
    return Math.ceil(hours / 24) * 30; // $30/day
  }
}

Key Takeaways

  1. Start with clear entities and relationships
  2. Use Singleton for ParkingLot
  3. Strategy for flexible fee calculation
  4. Discuss thread safety for concurrent access
  5. Keep it extensible for new vehicle types and spot sizes

Comments