Bird
Raised Fist0

Which design approach best uses the Parking Strategy Pattern to handle this complexity?

hard📝 Trade-off Q15 of Q15
LLD - Design — Parking Lot System
You want to design a parking system that supports multiple vehicle types (car, bike, truck) and different parking strategies (nearest, random, reserved). Which design approach best uses the Parking Strategy Pattern to handle this complexity?
ACreate separate parking lot classes for each vehicle type and hardcode the strategy inside each
BUse a single ParkingLot class with a strategy interface; implement different strategies and select based on vehicle type at runtime
CStore all vehicles in one list and assign spots randomly without strategy pattern
DUse global variables to track vehicle types and apply strategies in procedural code
Step-by-Step Solution
Solution:
  1. Step 1: Identify need for flexibility and scalability

    Supporting multiple vehicle types and strategies requires flexible design without code duplication.
  2. Step 2: Apply strategy pattern with runtime selection

    Using one ParkingLot class with strategy interface allows swapping strategies dynamically based on vehicle type.
  3. Step 3: Evaluate other options

    Create separate parking lot classes for each vehicle type and hardcode the strategy inside each duplicates code, C ignores strategy pattern, D uses poor global state management.
  4. Final Answer:

    Use a single ParkingLot class with a strategy interface; implement different strategies and select based on vehicle type at runtime -> Option B
  5. Quick Check:

    Strategy pattern + runtime selection = best design [OK]
Quick Trick: Use one class + strategy interface + runtime choice [OK]
Common Mistakes:
MISTAKES
  • Duplicating classes per vehicle type
  • Ignoring strategy pattern benefits
  • Using global variables instead of OOP

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes