Bird
0
0

In a system using the Strategy pattern, how can you combine it with the Factory pattern to improve scalability?

hard📝 Trade-off Q9 of 15
LLD - Behavioral Design Patterns — Part 1
In a system using the Strategy pattern, how can you combine it with the Factory pattern to improve scalability?
AUse Factory pattern to replace Context class.
BUse a Factory to create Strategy instances based on input, then inject into Context.
CReplace Strategy pattern with Factory pattern entirely.
DAvoid using Factory; create strategies manually everywhere.
Step-by-Step Solution
Solution:
  1. Step 1: Understand combining patterns

    Factory pattern creates objects without exposing creation logic.
  2. Step 2: Apply to Strategy pattern

    Using Factory to create Strategy objects based on input decouples creation from usage, improving scalability and maintainability.
  3. Final Answer:

    Use a Factory to create Strategy instances based on input, then inject into Context. -> Option B
  4. Quick Check:

    Factory creates strategies; Context uses them [OK]
Quick Trick: Factory creates strategies; Context uses them [OK]
Common Mistakes:
MISTAKES
  • Replacing Strategy with Factory
  • Confusing roles of Context and Factory
  • Creating strategies manually everywhere

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes