educative.io

How Design Patterns - Selected for Parking Lot?

The following design patterns can be used to design the parking lot system:

  • Singleton design pattern
  • Abstract Factory design pattern
  • Factory design pattern

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

Hi @Thirumavalavan,

In the design of the Parking Lot System, we can consider the following design patterns:

  1. Singleton Design Pattern: The Singleton pattern can be applied to ensure that there is only one instance of the ParkingLot class. Since a parking lot typically represents a single physical location, having multiple instances of it would not make sense. By using the Singleton pattern, we can guarantee that there’s a single, globally accessible instance of the parking lot.
  2. Abstract Factory Design Pattern: The Abstract Factory pattern can be utilized to create families of related objects, such as different types of vehicles (Car, Truck, Van, Motorcycle), parking spots (Handicapped, Compact, Large, Motorcycle), and payment methods (Cash, Credit Card). This pattern allows us to create these objects consistently and ensure they are compatible with each other within the system.
  3. Factory Design Pattern: The Factory pattern can be applied when creating instances of various objects like parking tickets, payment methods, and more. For example, when a vehicle enters the parking lot, a ParkingTicket object needs to be created. By using a factory method, we can encapsulate the creation logic and produce the appropriate object based on the given circumstances.

These design patterns help in organizing and structuring the components of the parking lot system, ensuring flexibility, maintainability, and adherence to object-oriented design principles.

Happy Learning :blush: