Requirements

Determine the different ways the system will be used. This includes main functions the system needs to perform and who will use it.


Who are the users:

  • People parking their cars


What are the core features:

  • Spot assignment based on size
  • Spot availability checking
    • Users should be able to see where spots are available
  • Fee calculation
    • Different rates may be applied to different vehicle types


What are the constraints:

  • n number of parking spots on n floors


Define Core Objects

Based on the requirements and use cases, identify the main objects of the system...


  • User
  • Vehicle (Motorcycle, sedan, SUV)
  • Garage
  • Garage floor
  • Parking space
  • Ticket


Analyze Relationships

Determine how these objects will interact with each other to fulfill the use cases...


  • A User can check parking availability for a garage
  • The garage will keep track of how many floors it has
  • The garage floors will handle assigning one of their spaces to a vehicle
  • When the user enters the garage, they are given a ticket with an assigned space
  • When a space is assigned, it stores a reference to the vehicle which occupies it, and marks itself as occupied
  • When a vehicle leaves the garage, the fee is calculated, the ticket is paid, and the parking space is released



  • A vehicle can be either small, medium or large
    • Types of vehicles will have additional identifiers


Establish Hierarchy

Design inheritance trees where applicable to promote code reuse and polymorphism. This step involves identifying common attributes and behaviors that can be abstracted into parent classes...


Common attributes:

  • Vehicles:
    • Some identifier(license plate)
    • Some size (sm/md/large) to correlate with a parking space

Common behaviors:

  • Vehicles:
    • Can be ticketed





Design Patterns

Consider using design patterns (e.g., Factory, Singleton, Observer, Strategy) that fit the problem...


Factory pattern:

  • Vehicles created with factory

Observer pattern:

  • Subject: Garage (Broadcasts how many spaces are available)
  • Observers: Users (To see availability)

Strategy pattern:

  • Context: Paying a ticket
  • Strategy: Dependent on type of vehicle

Singleton pattern:

  • Only one instance of garage will exist



Define Class Members (write code)

Attributes: For each class, define the attributes (data) it will hold...

Methods: Define the methods (functions) that operate on the attributes. Ensure they align with the object's responsibilities and adhere to the principle of encapsulation.


from abc import ABC, abstractmethod from datetime import datetime class User: def init(self, id): self.userId = id class Vehicle(ABC): def init(self, license): self.license = license @property @abstractmethod def hourlyRate(self): pass class Car(Vehicle): hourlyRate = 10 def __init__(self, license, make, model, size): super().__init__(license) self.make = make self.model = model self.size = size class Motorcycle(Vehicle): hourlyRate = 5 def __init__(self, license): super().__init__(license) self.size = "moto" class Garage: def init(self, id, floors): self.id = id self.floors = [GarageFloor(f) for f in range(floors)] def getSummary(self): spaces = {} for f in self.floors: for s in f.spaces: spaces[s.size] = spaces.get(s.size, 0) + 1 return spaces class GarageFloor: def init(self, level, spaces): self.level = level self.spaces = [] # Create n spaces of each type for t, n in spaces: for i in range(1, n + 1): spaces.append(ParkingSpace(i, t)) def getAvailableSpace(self, size): for s in self.spaces: if s.size == size: return s class ParkingSpace: def init(self, number, size): self.number = number self.size = size self.isOccupied = False def parkCar(self): self.isOccupied = True def releaseSpace(self): self.vehicle = None self.isOccupied = False class Ticket: def init(self, v: Vehicle, space: ParkingSpace): self.startTime = datetime.now() self.vehicle = v self.space = space space.parkCar() # Space assigned when a ticket is made def calculateFee(self) -> float: self.endTime = datetime.now() return (self.endTime - self.startTime) * self.v.hourlyRate






Adhere to SOLID Guidelines

Check and explain whether your design adheres to solid principles (Ask interviewer what SOLID principle is if you can not recall it.)...






Consider Scalability and Flexibility

Explain how your design can handle changes in scale and whether it would be easily to extend with new functionalities...






Create/Explain your diagram(s)

Try creating a class, flow, state and/or sequence diagram using the diagramming tool. Mermaid flow diagrams can be used to represent system use cases. You can ask the interviewer bot to create a starter diagram if unfamiliar with the tool. Briefly explain your diagrams if necessary...






Future improvements

Critically examine your design for any flaws or areas for future improvement...