Design a Grocery Store System
MediumReal World SystemsObserverStrategyFactory
Problem Statement
Design a grocery store checkout system that handles:
- Product catalog with categories and prices
- Shopping cart management
- Multiple checkout lanes (regular, self-checkout, express)
- Promotions and discounts (BOGO, percentage off, bulk discount)
- Loyalty points system
- Inventory management
Design Requirements
Key Entities:
Product— SKU, name, price, category, stockShoppingCart— Holds CartItems, calculates totalsCheckoutLane— Processes payment, applies discountsPromotion— Various discount strategiesLoyaltyAccount— Tracks and redeems pointsInventory— Manages stock levels, alerts on low stock
Key Behaviors:
addToCart(productId, quantity)→ adds to cart if in stockapplyPromotion(promotionCode)→ applies discountcheckout(cart, paymentMethod)→ processes sale, updates inventorygetReceipt()→ itemized receipt with discounts
!Constraints
- Product price precision: 2 decimal places
- Promotions: BOGO (buy one get one), 10-50% off, bulk (buy 3 get 20% off)
- Loyalty points: earn 1 point per $1 spent, redeem 100 points = $1
- Express lane: max 15 items
- Inventory alert when stock < 10 units
Output
Run your code to see output here.