Bird
0
0

Why is the Parking Strategy Pattern preferred over hardcoding parking logic directly in the Parking Lot class?

easy🧠 Conceptual Q10 of 15
LLD - Design — Parking Lot System
Why is the Parking Strategy Pattern preferred over hardcoding parking logic directly in the Parking Lot class?
AIt reduces the number of parking spots physically available.
BIt makes the parking lot code longer and more complex.
CIt improves flexibility and allows easy addition of new parking algorithms.
DIt forces all vehicles to park in the same spot.
Step-by-Step Solution
Solution:
  1. Step 1: Understand drawbacks of hardcoding

    Hardcoding makes changing parking logic difficult and error-prone.
  2. Step 2: Benefits of strategy pattern

    Strategy pattern separates logic, making it easy to add or change algorithms without touching core code.
  3. Final Answer:

    It improves flexibility and allows easy addition of new parking algorithms. -> Option C
  4. Quick Check:

    Strategy pattern = flexible, extensible design [OK]
Quick Trick: Strategy pattern = flexible, easy to extend [OK]
Common Mistakes:
MISTAKES
  • Thinking it reduces physical spots
  • Assuming it complicates code unnecessarily
  • Believing it forces same spot parking

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes