Bird
0
0

Which class should handle the calculation of the total price of all items in a shopping cart?

easy📝 Conceptual Q1 of 15
LLD - Design — Online Shopping Cart
Which class should handle the calculation of the total price of all items in a shopping cart?
ACart class
BProduct class
COrder class
DUser class
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of the Cart class

    The Cart class holds multiple products and their quantities, so it is responsible for aggregating prices.
  2. Step 2: Identify where total price calculation belongs

    Since the Cart manages the collection of products, it should calculate the total cost of all items.
  3. Final Answer:

    The Cart class handles total price calculation -> Option A
  4. Quick Check:

    Price calculation = Cart class [OK]
Quick Trick: Cart manages products and quantities, so it calculates totals [OK]
Common Mistakes:
  • Thinking Product calculates total for all items
  • Assigning total calculation to Order
  • Confusing User class with Cart

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes