Bird
0
0

How would you design the Order class to handle multiple payment methods (e.g., credit card, PayPal) while keeping the design scalable?

hard📝 Trade-off Q8 of 15
LLD - Design — Online Shopping Cart
How would you design the Order class to handle multiple payment methods (e.g., credit card, PayPal) while keeping the design scalable?
AUse a Payment interface and let Order hold a Payment object
BAdd separate attributes for each payment method in Order
CStore payment details as plain strings in Order
DLet Cart handle payment methods instead of Order
Step-by-Step Solution
Solution:
  1. Step 1: Understand scalability in payment handling

    Adding attributes for each payment method is not scalable as new methods require code changes.
  2. Step 2: Use interface-based design

    Defining a Payment interface and letting Order hold a Payment object allows easy extension for new methods.
  3. Final Answer:

    Use a Payment interface and let Order hold a Payment object -> Option A
  4. Quick Check:

    Interface-based design = scalable payment handling [OK]
Quick Trick: Use interfaces to support multiple payment types flexibly [OK]
Common Mistakes:
  • Hardcoding payment attributes
  • Storing payment as strings
  • Assigning payment to Cart

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes