Katkat

Design the Domain Model for an Automated Parking Garage

WayfairSoftware Engineer · Onsite

Last updated

This problem tests object-oriented design skills by requiring the modeling of physical interactions (vehicles, spots, sensors) and transactional state management in an automated parking system.

Problem Statement

Design an object-oriented domain model for an automated parking garage system. The system manages a multi-level structure with various parking spot sizes (Compact, Large, Handicapped). Vehicles enter the garage, are assigned a spot by the system, and exit after paying.

Requirements

  1. Define the core entities (e.g., Garage, Level, Spot, Ticket, Vehicle).
  2. Implement a mechanism to assign the 'optimal' spot for a vehicle based on its size.
  3. Ensure the system handles concurrent requests to prevent two vehicles from being assigned the same spot.
  4. Define the state lifecycle of a Ticket.

Constraints

  • Assume the garage has L levels, each with S spots.
  • Each spot has a size and a status (Available, Occupied, Reserved).
  • The system must support entry and exit logging for auditing.

Example Interaction

# Expected interface pattern:
class ParkingGarage:
    def assign_spot(self, vehicle: Vehicle) -> Optional[Ticket]:
        # Logic to find optimal spot and reserve it
        pass

    def process_exit(self, ticket: Ticket) -> float:
        # Logic to calculate fee based on duration
        pass

Edge Cases to Consider

  • The garage is full: What should the system return?
  • A vehicle loses its ticket: How does the system verify ownership?
  • Sensor failure: What happens if a spot shows occupied but the car is gone?

Hints

Hint 1

Use the Strategy pattern to encapsulate the 'optimal spot' search logic, allowing for different algorithms like 'closest to exit' or 'least full level'.

Hint 2

Model the `Ticket` as a state-machine entity to track its lifecycle from `ISSUED` to `PAID` to `CLOSED`.

Hint 3

Address thread safety by using a locking mechanism or an atomic database transaction at the `Spot` level when setting its status to `OCCUPIED`.

Follow-up questions

  • How would you modify your design to support electric vehicle charging stations, where the duration of stay is tied to energy consumption?
  • If the system requires a real-time dashboard for site managers, how would you propagate state changes from the parking spots to the UI?
  • How would you handle a scenario where the automated gate mechanism fails to open for a vehicle that has already paid for its stay?