Bird
Raised Fist0

Which of the following problems CANNOT be effectively solved by applying the Strategy Pattern to replace conditional logic?

easy🔍 Pattern Recognition Q2 of Q15
OOP & Design Patterns - Strategy Pattern - Replace Conditionals with Polymorphism
Which of the following problems CANNOT be effectively solved by applying the Strategy Pattern to replace conditional logic?
ASelecting different sorting algorithms at runtime based on data size
BAdding new behaviors without modifying existing code
CManaging object creation with complex dependencies and lifecycle
DSwitching payment methods dynamically without changing client code
Step-by-Step Solution
Solution:
  1. Step 1: Understand the scope of the Strategy Pattern

    It encapsulates interchangeable behaviors, not object creation or lifecycle management.
  2. Step 2: Identify the mismatch

    Managing object creation with complex dependencies is handled by Factory or Dependency Injection patterns, not Strategy.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Strategy replaces behavior, not object creation [OK]
Quick Trick: Strategy replaces behavior, not object creation [OK]
Common Mistakes:
MISTAKES
  • Confusing Strategy with Factory
  • Thinking Strategy manages object lifecycle
Trap Explanation:
PITFALL
  • Candidates often confuse Strategy with Factory, picking object creation as solvable by Strategy.
Interviewer Note:
CONTEXT
  • Tests anti-pattern recognition and pattern applicability understanding.
Master "Strategy Pattern - Replace Conditionals with Polymorphism" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes