Bird
0
0

In a system where multiple payment methods exist, how can behavioral patterns help manage payment processing dynamically?

hard📝 Trade-off Q9 of 15
LLD - Behavioral Design Patterns — Part 1
In a system where multiple payment methods exist, how can behavioral patterns help manage payment processing dynamically?
AUse Composite pattern to group payment methods
BUse Strategy pattern to select payment algorithm at runtime
CUse Singleton pattern to restrict payment processing to one instance
DUse Adapter pattern to convert payment data formats
Step-by-Step Solution
Solution:
  1. Step 1: Understand dynamic selection need

    Strategy pattern allows choosing different payment algorithms at runtime.
  2. Step 2: Rule out other patterns

    Adapter changes interface; Singleton restricts instances; Composite groups objects but doesn't select behavior.
  3. Final Answer:

    Use Strategy pattern to select payment algorithm at runtime -> Option B
  4. Quick Check:

    Strategy = dynamic algorithm selection [OK]
Quick Trick: Strategy pattern picks algorithms dynamically [OK]
Common Mistakes:
MISTAKES
  • Confusing Adapter with behavioral pattern
  • Using Singleton for behavior control
  • Misapplying Composite for behavior selection

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes