Bird
0
0

Which of the following is the correct way to add a product to a cart in a typical class design?

easy📝 Conceptual Q12 of 15
LLD - Design — Online Shopping Cart
Which of the following is the correct way to add a product to a cart in a typical class design?
Aorder.addProduct(product, quantity)
Bproduct.addToCart(cart, quantity)
Ccart.addProduct(product, quantity)
Dcart.createOrder(product, quantity)
Step-by-Step Solution
Solution:
  1. Step 1: Identify the class responsible for holding selected products

    The Cart class holds selected products and their quantities before purchase.
  2. Step 2: Check method naming conventions

    Adding a product to a cart is typically done by calling a method on the Cart object, like addProduct(product, quantity).
  3. Final Answer:

    cart.addProduct(product, quantity) -> Option C
  4. Quick Check:

    Adding product to cart = cart.addProduct() [OK]
Quick Trick: Add products via Cart methods, not Product or Order [OK]
Common Mistakes:
  • Calling addToCart on Product class
  • Using Order class to add products before purchase
  • Confusing method names like createOrder in Cart

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes