Design an object-oriented shopping cart module for an e-commerce system.
Requirements:
-
A cart can
add items
and
update item quantities
.
-
The cart supports
checkout
. After checkout, the cart becomes
immutable
(no further changes to items/quantities/coupons).
-
The cart can
apply coupons
. There may be multiple coupon types, for example:
-
Percentage off
(e.g., 20% off)
-
BOGO
(Buy-One-Get-One) style discounts
-
The cart must compute
tax
based on a
state tax rate
.
-
The prompt is intentionally vague: explain what clarifying questions you would ask, then propose a clean class/interface design and describe how totals are calculated.
Deliverables:
-
Key classes and responsibilities (e.g., Cart, LineItem, Product, Pricing/Discount/Tax components).
-
Core methods and data structures.
-
How you prevent modification after checkout.
-
How you model different coupon types and make it easy to add new ones.