Bird
0
0

Why does the Strategy pattern promote the Open/Closed Principle in software design?

hard🧠 Conceptual Q10 of 15
LLD - Behavioral Design Patterns — Part 1
Why does the Strategy pattern promote the Open/Closed Principle in software design?
ABecause it forces all algorithms to be written in one class.
BBecause new strategies can be added without modifying existing code.
CBecause it prevents any changes to the Context class.
DBecause it removes the need for interfaces.
Step-by-Step Solution
Solution:
  1. Step 1: Recall Open/Closed Principle

    Software entities should be open for extension but closed for modification.
  2. Step 2: Relate to Strategy pattern

    Strategy pattern allows adding new algorithms (strategies) by creating new classes without changing existing code.
  3. Final Answer:

    Because new strategies can be added without modifying existing code. -> Option B
  4. Quick Check:

    Strategy supports Open/Closed by extension without modification [OK]
Quick Trick: Add new strategies without changing old code [OK]
Common Mistakes:
MISTAKES
  • Thinking all algorithms in one class
  • Believing Context cannot change
  • Assuming interfaces are removed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes