OOPL2 · Easy
Relationships: Order – Item – Payment
Problem
Model an e-commerce Order to understand the three types of object relationships: Composition (Order owns LineItems — items cannot exist without the order), Aggregation (Order references a Customer — customer exists independently), and Association (Order uses a Payment — payment can outlive the order).
Requirements
- ▸Order COMPOSES LineItems — LineItem has no meaning outside an Order
- ▸Order AGGREGATES a Customer — Customer exists independently
- ▸Order ASSOCIATES with Payment — Payment is separate, can reference multiple orders
- ▸Order.addItem(product, qty) — adds LineItem internally
- ▸Order.calculateTotal() — sums all LineItem prices
- ▸Order.placeOrder(payment) — validates and creates a payment record
- ▸Customer.getOrderHistory() — returns all orders for this customer
Constraints
- –LineItem cannot be created outside Order context (make constructor package-private or use factory on Order)
- –Deleting an Order should also delete its LineItems (cascade)
- –Deleting an Order should NOT delete the Customer or Payment
✓ Saved