DEV Community

Cover image for A Deep Dive into Parking Spot LLD Design
mrityunjay saraf
mrityunjay saraf

Posted on

A Deep Dive into Parking Spot LLD Design

Greetings, dear reader! ๐ŸŒŸ

In this blog, we're crafting functional and super-efficient parking spots. And guess what? We're diving into design patterns to make them even smarter and more effective. So reading.start()๐Ÿš—๐Ÿ’ก

Responsibility

๐Ÿš— Vehicle Entry and Exit: Finding the appropriate parking spot for the vehicle and creating the ticket.

๐Ÿ…ฟ๏ธ Parking Spot Allocation: Efficiently allocate available parking spots to incoming vehicles based on factors like size, type, and user preferences.

๐Ÿ’ฐ Cost Computation and Payment: Calculate parking costs based on duration and vehicle type, offering flexible payment options for users.

๐Ÿ† Parking Strategy Options: Different parking strategies (e.g., park near entrance, park near elevator) should be available to users and prioritize spot allocation based on user preferences and vehicle type.

Our Parking Model Lineup ๐ŸŒŸ

  1. ParkingSpot ๐Ÿ…ฟ๏ธ
  2. Vehicle ๐Ÿš—
  3. ParkingSpotManager (EntranceManager and ExitManager) ๐Ÿ…ฟ๏ธ
  4. Ticket ๐ŸŽซ
  5. ParkingSpotType and VehicleType (enum) ๐Ÿš—
  6. ParkingStrategy ๐Ÿšฆ
  7. CostConfiguration ๐Ÿ’ธ
  8. CostComputationStrategy๐Ÿ’ฐ

ParkingSpot Interface ๐Ÿš—๐Ÿ๏ธ

๐Ÿš™ The ParkingSpotManager holds a collection of ParkingSpot catering to various Vehicle types (2-wheelers and 4-wheelers).

๐Ÿ› ๏ธ To achieve this, we'll create an interface that Concrete Classes (like twoWheelerParkingSpot and FourWheelerParkingSpot) can implement.

๐Ÿ Additionally, it employs a ParkingSpotType enumeration to categorize the types of parking spots available.

๐Ÿš€ The benefit of employing this interface is that if we decide to introduce a new type of parking spot later on, we can simply create a class that adheres to the interface.

Image description

๐Ÿ…ฟ๏ธParkingManager: Central hub for parking spot management, handling addition/removal, spot allocation, ticket creation, and price computation.

๐Ÿš—EntranceManager: This manager is responsilbe for efficiently allocating parking spots to incoming vehicles based on vehicle types and parking strategies and Generating the ticket.

๐Ÿšฆ ExitManager: Calculate parking fees using a Cost computation strategy considering duration and spot type.

Image description

Finding the Right Spot for you Vehicle ๐Ÿš—

๐Ÿš€Imagine the EntranceManager as a matchmaker for vehicles.

๐ŸŽฏ It take two parameter: a vehicle to know vehicle type, and a ParkingStrategy to understand the user preference.

๐Ÿ’กUsing this, it finds the right parking spot and makes a ticket for that vehicle and strategy.

๐ŸšซAfter the successfull allocation of the spot, the spot in marked as the occupied and hence not available for the other Vehicle.

๐ŸŽ‰ Unraveling the Magic:
You might notice our usage of

Optional<Ticket>
Enter fullscreen mode Exit fullscreen mode

In essence, an Optional acts as a container that may or may not hold a ticket. Optional are used to avoid null check if object not found

Image description

๐ŸŽฉ Exit Manager: Calculate your Parking Fare!

๐Ÿš— When your trusty vehicle bids adieu and rolls out from the parking haven, the Exit Manager springs into action.

๐Ÿ’ฐBy summoning the mighty Cost Computation Strategy (including the HourlyCostComputation and DailyCostComputation) and your ride Duration ,it crafts a fair and fancy price tag๐Ÿค‘.

Image description

After we have combined all the stuff here is the complete Diagram.

Image description

๐ŸŒŸ Thanks for joining our parking adventure!๐Ÿ˜Š

๐Ÿ’ฌ If you enjoyed reading this blog,please take a moment to share your thoughts by leaving a review and liking it ๐Ÿ˜€

๐Ÿš— Stay tuned for our next blog, where we'll dive into an exciting coding demo of this smart parking system. Keep your engines running! ๐ŸŽ‰

Top comments (4)

Collapse
 
mahimarajput profile image
MahimaRajput

Very well explained!

Collapse
 
mjsf1234 profile image
mrityunjay saraf

thanks๐Ÿ˜Š

Collapse
 
princekr11 profile image
princekr11

nice blog@mjsf1234, kept my engines in the air!

Collapse
 
mjsf1234 profile image
mrityunjay saraf

thanks prince