Parking Lot [Low Level Design]
Use Cases :
2 min readJun 13, 2023
- Generate Ticket when vehicle enters
- Generate price when vehicle exit
Few question needs to ask with Interviewer :
- Candidate : What details should be in ticket ?
Interviewer : Vehicle Number,Entry Time,Exit Time,Parking Spot Id and unique id for tracking - Candidate : How do we allocate parking to vehicle ?
Interviewer : At the time when vehicle enters - Candidate : Are there different type of parking ?
Interviewer : Yes, 2 Wheeler,4 Wheeler - Candidate : How we are deciding parking spot ?
Interviewer : We can have multiple strategies like min distance, near lift, first come first serve. - Candidate : How we are generating price ?
Interviewer : It can have different strategies like based on parking spot (2 Wheeler -> 40 Rs, 4 Wheeler -> 100 Rs), Hourly basis/minute basis
Entity :
- Ticket -> id, vehicle, parkingSpot, entryTime, exitTime
- Vehicle : id, number
- Parking Spot -> id, state, vehicleType
- State (enum) -> OCCUPIED,UNOCCUPIED
- VehicleType -> TWO_WHEELER,FOUR_WHEELER
APIs :
- Parking Service
package systemDesign.ParkingLot;
import systemDesign.ParkingLot.model.Ticket;
import systemDesign.ParkingLot.model.Vehicle;
public interface ParkingService {
Ticket entry(Vehicle vehicle);
double exit(long ticketId);
}
2. Slot Service
package systemDesign;
import systemDesign.ParkingLot.model.ParkingSlot;
import systemDesign.ParkingLot.model.Ticket;
public interface SlotService {
ParkingSlot allocate(Ticket ticket);
boolean unallocate(int parkigSlotId);
}
3. Pricing Service
package systemDesign;
import systemDesign.ParkingLot.model.Ticket;
import java.util.Date;
public interface PricingService {
double generatePrice(Ticket ticket, Date exitTime);
}
Thanks for reading !! Happy Learning !!