Problem Statement
How do aggregation and composition guide your class design in LLD for an Order module?
Explanation
Use composition when an Order strictly owns its OrderItems. Deleting the Order deletes its items. This encodes lifecycle rules in the model itself and prevents orphan records.
Use aggregation for looser ties, like Order referencing a Customer that exists independently. This keeps identity boundaries clear and avoids unintended cascading deletes.
Code Solution
SolutionRead Only
Order ◼─ OrderItem (composition) Order ◇─ Customer (aggregation)
