Parking Lot LLD | Is this approach enough for interviews? | Feedback appreciated
5112

Parking Lot - Low Level Design

Requirements:

  1. A parking lot has limited number of parking spots available.
  2. The parking spot is based on the vehicle size. A small vehicle can be parked in a parking slot meant for big vehicle but not vice versa.
  3. The system should be assigning the nearest parking space available which is specific to the vehicle size.
  4. System should provide all the current used spots and the vehicle information.
  5. System should provide all the current available spots.
  6. System should assign a ticket once the vehicle is assigned a spot and mark the ticket as paid once the vehicle exits the spot.

Entities:
Slot
Vehicle
VehicleSize
SlotType
Ticket
ParkingLot
TicketStatus

User-Defined types:

SlotType - SMALL, MEDIUM, LARGE
SlotStatus - AVAILABLE, OCCUPIED, WORK_IN_PROGRESS
VehicleSize - CAR, JEEP, TRUCK
TicketStatus - ISSUED, PAID

Domain classes:

class Slot {
	int slotNumber;
	SlotType slotType;
	SlotStatus slotStatus;
	
	void setSlotStatus(SlotStatus slotStatus) {}
}

class Vehicle {
	String registrationNumber;
	VehicleSize vehicleSize;
}

class Ticket {
	String ticketNumber;
	Vehicle vehicle;
	int slotNumber;
	TicketStatus ticketStatus;
	DateTime issuedTime;
	DateTime exitTime;
	
	void setTicketStatus(TicketStatus ticketStatus){}
	void setExitTime(DateTime exitTime) {}
}

class VehicleSlotMapper {
	Map<VehicleType, SlotType> vehicleSlotMap;
	
	static List<SlotType> getMatchingSlotsForVehicle(VehicleType vehicleType){}
}

class ParkingLot {
	SlotManager slotManager;
	AssignmentStrategy assignmentStrategy;
	TicketManager ticketManager;
	
	Ticket parkVehicle(Vehicle vehicle) {}
	void payTicket(Ticket ticket) {}
}

class SlotManager {
	List<Slot> slots;
	Map<Slot, Ticket> usedSlotVehicleMap;	

	void createSlot(SlotType slotType) {}
	void assignSlotToVehicle(Slot slot, Ticket ticket) {}
	List<Slot> getAllSlots(){}
	List<Slot> getAvailableSlots(){}
	Map<Slot, Ticket> getUsedSlotVehicleInfo(){}
	void makeSlotAvailable(Slot slot) {}
}

class TicketManager {
	Map<String, Ticket> tickets;
	
	void createTicket(Vehicle vehicle, int slotNumber, DateTime issuedTime){}
	void markTicketAsPaid(Ticket ticket) {}
}

interface AssignmentStrategy {
	
	Slot assignParkingSpace(List<Slot> slots, Vehicle vehicle);
}

class NearestSizeAppropriate implements AssignmentStrategy {
	
	Slot assignParkingSpace(List<Slot> slots, Vehicle vehicle) {
	}
}

Possible extensions (yet to implement):

  1. Parking lot has many levels. How will you implement it?
  2. How will you implement the per hour payment for each type of vehicle?
  3. How will you ensure that the same parking space is not assigned to two or more vehicles?
Comments (3)