Bird
0
0

You want to combine two strategies: NearestSpotStrategy and ElectricVehicleStrategy. How can you design the system to apply both?

hard📝 Trade-off Q9 of 15
LLD - Design — Parking Lot System
You want to combine two strategies: NearestSpotStrategy and ElectricVehicleStrategy. How can you design the system to apply both?
ACreate two separate parking lots for each strategy.
BUse only NearestSpotStrategy and ignore electric vehicle needs.
CSwitch strategies randomly for each vehicle.
DImplement a composite strategy that first applies ElectricVehicleStrategy, then NearestSpotStrategy.
Step-by-Step Solution
Solution:
  1. Step 1: Understand combining strategies

    Composite pattern allows combining multiple strategies in sequence.
  2. Step 2: Apply composite to parking strategies

    First check if vehicle is electric and assign charging spot, else assign nearest spot.
  3. Final Answer:

    Implement a composite strategy that first applies ElectricVehicleStrategy, then NearestSpotStrategy. -> Option D
  4. Quick Check:

    Composite strategy combines multiple behaviors [OK]
Quick Trick: Use composite pattern to combine strategies [OK]
Common Mistakes:
MISTAKES
  • Ignoring electric vehicle needs
  • Randomly switching strategies
  • Splitting parking lots unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes