Loading...
Learn Design Parking Lot — a key concept for LLD interviews.
You're building a parking garage app for a busy mall. The garage has 3 floors with 500 spots total. Cars, motorcycles, and trucks all need parking — but they take different amounts of space. You need a clean class design to represent vehicles.
// Option A: Single class with type field
class Vehicle {
type: 'car' | 'motorcycle' | 'truck'
licensePlate: string
spotsNeeded: number
}
// Option B: Abstract base + concrete subclasses
abstract class Vehicle {
abstract spotsNeeded: number
licensePlate: string
}
class Car extends Vehicle { spotsNeeded = 1 }
class Motorcycle extends Vehicle { spotsNeeded = 1 }
class Truck extends Vehicle { spotsNeeded = 2 }Which approach best models the vehicle types?