Bird
Raised Fist0

Which design approach best supports this requirement, given that the naive Strategy Pattern supports only one strategy at a time?

hard📘 Fundamental Understanding Q10 of Q15
OOP & Design Patterns - Strategy Pattern - Replace Conditionals with Polymorphism
You want to enhance a payment system to allow splitting a single payment across multiple payment strategies simultaneously (e.g., part credit card, part UPI). Which design approach best supports this requirement, given that the naive Strategy Pattern supports only one strategy at a time?
ASingleton Pattern to manage payment instances
BComposite Pattern to combine multiple strategies
CObserver Pattern to notify multiple strategies
DFactory Pattern to create a single strategy
Step-by-Step Solution
Solution:
  1. Step 1: Understand limitation of Strategy Pattern

    The Strategy Pattern supports only one algorithm at a time.
  2. Step 2: Identify suitable pattern for multiple strategies

    The Composite Pattern allows treating multiple strategies as one combined object.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Composite combines multiple strategies into one object [OK]
Quick Trick: Composite combines multiple strategies into one [OK]
Common Mistakes:
MISTAKES
  • Choosing Singleton which controls instance uniqueness
  • Observer is for event notification, not combining algorithms
  • Factory creates single instances, not composites
Trap Explanation:
PITFALL
  • Mistaking Singleton or Factory for multi-strategy support
Interviewer Note:
CONTEXT
  • Tests knowledge of design patterns beyond Strategy for complex requirements
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