educative.io

When a new car arrives, which class checks for empty parking spot

Suppose a new car comes to the entry gate.
Which class will look for empty parking space?
And how will it check the parking space type is similar to the car type?


Course: Grokking the Low Level Design Interview Using OOD Principles - Learn Interactively
Lesson: Code for the Parking Lot - Grokking the Low Level Design Interview Using OOD Principles

Hi @Amartya_Roy !!
In the given design of the parking lot system, when a new car arrives at the entry gate, the class responsible for looking for an empty parking space and checking if the parking space type is suitable for the car type is the ParkingLot class.

Here’s how it works:

  1. Vehicle Arrival at Entry Gate:

    • When a new car arrives at the entry gate, the entry gate (which is an instance of the Entrance class) will interact with the ParkingLot class to obtain a parking ticket for the car.
  2. Getting a Parking Ticket:

    • The Entrance class will call a method in the ParkingLot class to request a parking ticket for the arriving car.
    • The ParkingLot class, in response, will handle the process of finding an empty parking spot for the car.
  3. Finding an Empty Parking Spot:

    • Inside the ParkingLot class, the method responsible for finding an empty parking spot will be invoked.
    • This method will iterate through the available parking spots (of different types, e.g., handicapped, compact, large) to check if there is an available spot suitable for a car. It will typically check if the parking spot is free and if it matches the type of the arriving vehicle (in this case, a car).
  4. Assigning the Parking Spot:

    • Once an empty and suitable parking spot is found, the ParkingLot class will assign this spot to the arriving car. It will mark the spot as occupied and associate it with the car.
  5. Issuing a Parking Ticket:

    • After successfully assigning a parking spot, the ParkingLot class will generate a parking ticket for the car. This ticket will include information about the parking spot, entry timestamp, and other relevant details.

By following this process, the ParkingLot class manages the allocation of parking spots based on the type of the arriving vehicle and ensures that only suitable spots are assigned to vehicles. This design allows for efficient parking spot allocation and tracking within the parking lot system.
I hope it helps. Happy Learning :blush: