System design · LLD design
Parking Lot
Functional requirements
- Support multiple floors with each floor having mulitple parking spots of different sizes
- Support three vehicle types with fixed size: SMALL, MEDIUM , LARGE
- Each parking spot has a size , and can accommodate vehicle of equal or small size
- On entry, find a parking spot for the vehicle based on nearest-to-entry-point assignment , assign to the vehicle and create a ticket
- If there is no parking spot left return some message
- On exit, validate the ticket , calculate the parking duration and fee and release the spot and return fee amount
Non-Functional Requriements
- Handle concurrent request from multiple gate safely without assigning the same spot
- Extensible logic for payment calculation and spot assignment
- System should support addition of more spots and floors
Entities and classes
1.Parking floor - which will store the floor and list of parking spots. Initialize with empty parking spot
-
int floor
-
list <ParkingSpot>
+addSpot()
2. ParkingSpot -
-int spotid - unique number generate
-isOccupied - initialize false
-VehicleSize size
+canFitVehicle()
+parkVehicle()
+unparkVehicle()
+isAvailable()
3.Vehicle -
-string licenseNumber
-VehicleSize size
4. VehicleSize - (enum) SMALL , MEDIUM , LARGE
5.ParkingTicket
-ticketId
-vehicleID
-parkingspot
-entryTime
-existTime
+updateExistTime()
6.Find the spot for assigning the vehicle
ParkingSpotAssignmentStrategy - interface
nearestToEntryPointStrategy - implement ParkingSpotAssignmentStrategy
+ findSpot(size)
7.FeeStrategy - interface
FlatRateFeeStrategy - implement FeeStrategy
-double RatePerHour;
+ calaculateRate();
8.ParkingLotSystem - (orchestrator class)
-parkingStrategy
-feeStrategy
-activeTickets
+addFloors()
+addSpot(floor)
+vehicleEntry() - assign spot , assign ticket
+vehicleExist() - feeamount, release parking spot
5.ParkingTicket
-ticketId
-vehicleID
-parkingspot
-entryTime
-existTime
+updateExistTime()
vehicleExist(vehicle v) {
Fetch the ticket -
If not valid ticket return some message like " in valid ticket found"
Update the end time to now - updateExistTime()
Release the spot - unparkVehicle() - parkingspot
Calculate the free using the feestategy - like for this we have add FlatRateFeeStrategy - in this it calculate the hour from entry time and current time
}
synchronized tryPark(vehicle v) {
if(canFit(v) ) -> parkvehicle(V)
}
Boolean canFit(vehicle v) {
Return v.size() <= spot.size()
}
parkVehicle(vehicle v){
parkedVehicle = v;
Occupied = true;
}