Design cart and pricing engine classes
Company: Uber
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Onsite
Design the core classes and interfaces for a cart & pricing engine for a food delivery marketplace (e.g., Uber Eats).
The final checkout price is not simply the sum of menu items. It is dynamically computed based on:
- **Item customizations**: add/remove ingredients, size upgrades, dietary substitutions. Each customization may add $0 or an extra cost.
- **Marketplace dynamics**: e.g., **surge pricing** as a multiplier applied to a subtotal (e.g., 1.2×).
- **Promotions**: coupon codes such as **$5 off**, **10% off**, **Buy 1 Get 1 Free (BOGO)**, and possibly tiered delivery fees.
- **Membership benefits**: e.g., subscribers get **0 delivery fee** and **5% off eligible items**.
Requirements:
1. **Cart operations**: add/remove items and quantities; apply item-level customizations.
2. **Flexible pricing strategies**: support multiple independent pricing rules (surge, membership discount, coupons, BOGO, delivery fee rules). Rules should be composable and easy to extend.
3. **Receipt breakdown**: return an itemized checkout receipt showing at least: base price, add-ons, fees, discounts, and final total.
Provide an object-oriented design: key classes, interfaces, and how they collaborate. Clarify how pricing rules are ordered/combined and how the receipt is produced.
Quick Answer: This question evaluates object-oriented system design and domain modeling skills related to cart operations, item customizations, composable pricing rules (surge, promotions, membership) and producing an itemized receipt.