Bird
Raised Fist0

You are designing a payment system that supports multiple payment methods (credit card, PayPal, cryptocurrency). How would applying the Strategy pattern improve your system design?

hard📝 Trade-off Q15 of Q15
LLD - Behavioral Design Patterns — Part 1
You are designing a payment system that supports multiple payment methods (credit card, PayPal, cryptocurrency). How would applying the Strategy pattern improve your system design?
AIt requires hardcoding all payment methods inside a single class
BIt forces all payment methods to share the same implementation details
CIt prevents runtime selection of payment methods
DIt allows adding new payment methods without changing existing code by defining each as a separate strategy
Step-by-Step Solution
Solution:
  1. Step 1: Understand Strategy pattern benefits in payment methods

    Strategy pattern lets you define each payment method as a separate strategy class implementing a common interface.
  2. Step 2: Analyze how this affects system design

    This design allows adding new payment methods easily without modifying existing code, and lets the system select payment method at runtime.
  3. Final Answer:

    It allows adding new payment methods without changing existing code by defining each as a separate strategy -> Option D
  4. Quick Check:

    Strategy pattern = easy extension and runtime choice [OK]
Quick Trick: Strategy pattern enables easy addition and runtime choice [OK]
Common Mistakes:
MISTAKES
  • Thinking Strategy forces shared implementation
  • Believing all methods must be hardcoded together
  • Assuming runtime selection is not possible

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes