Bird
0
0

Which design choice best supports scalability and clear responsibility?

hard📝 Trade-off Q15 of 15
LLD - Design — Online Shopping Cart
You want to design a system where a Cart can hold multiple Products with quantities, and an Order records the purchased items and status. Which design choice best supports scalability and clear responsibility?
AMake Cart store product IDs only; Order stores full product details and quantities
BMake Cart hold Product objects with quantities; Order copies Cart items and tracks status separately
CMake Product class hold quantity and add methods to update Cart and Order directly
DMake Order class inherit from Cart and add status and total cost fields
Step-by-Step Solution
Solution:
  1. Step 1: Understand separation of concerns

    Cart should hold selected products and quantities before purchase. Order should record purchased items and status separately.
  2. Step 2: Evaluate design options for scalability and clarity

    Make Cart hold Product objects with quantities; Order copies Cart items and tracks status separately keeps Cart holding Product objects with quantities, and Order copies these items to keep a snapshot and track status, which is clean and scalable.
  3. Final Answer:

    Make Cart hold Product objects with quantities; Order copies Cart items and tracks status separately -> Option B
  4. Quick Check:

    Separate Cart and Order responsibilities for scalability [OK]
Quick Trick: Keep Cart and Order responsibilities separate and clear [OK]
Common Mistakes:
  • Making Order inherit Cart causing tight coupling
  • Storing only product IDs in Cart losing details
  • Putting quantity in Product class mixing concerns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes