Problem statement
Design the object model and core APIs for a checkout pricing calculator that turns a cart of line items into a final total by applying line pricing, discounts, shipping, and taxes in a well-defined order, for a single store.
Operating context. Given a cart (line items with product and quantity), the calculator produces an itemized breakdown: line subtotals, line-level and order-level discounts, shipping, taxes, and a grand total. The calculation is an ordered pipeline of composable stages, and order matters (tax is computed after discounts). Volatile inputs — tax rates, shipping quotes, and already-resolved discounts — come from ports rather than being computed inline. The result must be deterministic and explainable, rounding must happen in one place, and pricing is read-heavy and concurrent. The whole thing is a single in-process component.
Out of scope. Authoring promotion/coupon rules (a stage consumes discounts that are already resolved), the payment step, inventory reservation, currency FX conversion, and persistence.
What to produce. The class hierarchy (Cart, LineItem, the pricing-stage abstraction and pipeline, the price-breakdown result, a Money value object, and the calculator facade), the public API each exposes, and the ordered stage flow. Be explicit about: how stages compose and can be reordered, how the breakdown stays explainable, and how rounding is centralized so no stage introduces float drift.
Requirements
The requirements come with Premium
PremiumThe statement above is free to read.