Bird
Raised Fist0

In designing a parking lot system using OOP, which component is best suited to decide which type of parking spot (e.g., compact, large, handicapped) should be allocated to an incoming vehicle?

easy🔍 Pattern Recognition Q11 of Q15
OOP & Design Patterns - Design a Parking Lot - LLD with OOP (Classes, Patterns, Extensibility)
In designing a parking lot system using OOP, which component is best suited to decide which type of parking spot (e.g., compact, large, handicapped) should be allocated to an incoming vehicle?
AThe ParkingLot class, as it manages all spots and vehicles
BThe ParkingSpot class, since it represents the spot's characteristics
CThe Vehicle class, because it knows its own size and type
DA Factory or Strategy pattern component that encapsulates the allocation logic
Step-by-Step Solution
  1. Step 1: Understand responsibilities

    The Vehicle class only knows about itself, not allocation rules. The ParkingSpot class represents a spot but doesn't decide allocation. The ParkingLot manages overall state but delegating allocation logic to a dedicated component improves modularity.
  2. Step 2: Recognize design pattern role

    The Factory or Strategy pattern encapsulates allocation logic, allowing easy extension and modification without changing core classes.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Allocation logic centralized -> easier to maintain and extend [OK]
Quick Trick: Allocation logic belongs in a dedicated pattern component, not core entities [OK]
Common Mistakes:
MISTAKES
  • Assigning allocation responsibility to Vehicle or ParkingSpot classes
  • Putting all logic inside ParkingLot class leading to tight coupling
Trap Explanation:
PITFALL
  • Options A and B seem plausible because they relate to vehicle and spot attributes, but they violate single responsibility and reduce extensibility. Option D is tempting but leads to monolithic design.
Interviewer Note:
CONTEXT
  • Tests candidate's understanding of responsibility assignment and design pattern application in OOP LLD
Master "Design a Parking Lot - LLD with OOP (Classes, Patterns, Extensibility)" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes