KatInterview

Multi-Level Parking Facility: Class Structure and Operations

Data Structure DesignModel answer
MediumModel answerData Structure Designobject-oriented-designSOLID-principlesdesign-patterns

Last updated

Model a parking facility with levels and sized spots, supporting vehicle entry/exit, spot allocation by compatibility, and availability queries.

You need to create an object-oriented model for managing a multi-level parking facility.

System Requirements:

The facility consists of multiple floors, where each floor contains a collection of parking spots. Spots come in three sizes: small, medium, and large. Vehicles arrive in different forms—motorcycles, cars, and buses/trucks—each with different space requirements.

Compatibility rules:

  • Motorcycles fit in any spot size
  • Cars require medium or large spots
  • Buses/trucks need multiple contiguous large spots on the same floor

Core Operations:

Your system must handle:

  1. Vehicle arrival: Locate and assign suitable spot(s) for an incoming vehicle, or indicate no space is available
  2. Vehicle departure: Release occupied spot(s) and compute the parking charge based on duration
  3. Status queries: Report available spot counts by size and floor, plus whether the facility has reached capacity

Design Scope:

Focus on the in-memory object model, not distributed system concerns. Assume timing and payment are provided by external utilities.

What to provide:

  • Core classes with their responsibilities and key fields
  • How classes relate (inheritance vs. composition)
  • Essential methods for the three operations above
  • Which design patterns or principles guide your choices
  • A complete implementation demonstrating your design

Hints

Hint 1

Consider using composition for the physical hierarchy (facility → floors → spots) and light inheritance for vehicle types

Hint 2

The compatibility check can be simplified if spot sizes form an ordered enumeration

Hint 3

Separate allocation logic from billing logic—one changes with physical constraints, the other with pricing policy