Bird
Raised Fist0

What is the main purpose of the Strategy pattern in system design?

easy🧠 Conceptual Q11 of Q15
LLD - Behavioral Design Patterns — Part 1
What is the main purpose of the Strategy pattern in system design?
ATo restrict object creation to a single instance
BTo allow selecting an algorithm's behavior at runtime without changing the client code
CTo define a fixed sequence of steps for an algorithm
DTo create a single global instance of a class
Step-by-Step Solution
Solution:
  1. Step 1: Understand the Strategy pattern goal

    The Strategy pattern is designed to let you swap algorithms or behaviors dynamically without changing the client code.
  2. Step 2: Compare options with pattern purpose

    To allow selecting an algorithm's behavior at runtime without changing the client code correctly states this purpose. Options A and B describe Singleton pattern, and C describes Template Method pattern.
  3. Final Answer:

    To allow selecting an algorithm's behavior at runtime without changing the client code -> Option B
  4. Quick Check:

    Strategy pattern = runtime algorithm selection [OK]
Quick Trick: Strategy pattern = choose behavior at runtime [OK]
Common Mistakes:
MISTAKES
  • Confusing Strategy with Singleton pattern
  • Thinking Strategy fixes algorithm steps
  • Assuming Strategy creates single instances

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes