Comparison
Aggregation vs compositionvsIs-a vs has-a
Aggregation vs composition
you deleted the order and the line items went with it, but the customer stayed, because only one of them belonged to it.
Two shades of has-a: composition means the part's lifetime is owned by the whole and it cannot be shared, aggregation means the whole merely holds a reference to something that outlives it. The distinction is drawn as a filled or hollow diamond in UML and is worth exactly as much as the lifetime consequence — what gets deleted, what gets copied, what can be handed to two owners at once. It becomes concrete rather than academic the moment you write a delete or a deep copy.
Full entry →Is-a vs has-a
you said it out loud — a Stack is a List — and it sounded fine right up until someone called insert in the middle of it.
The rough test for whether a relationship should be inheritance or a field: inheritance claims the subtype is usable everywhere the supertype is, while composition only claims it uses one. It is rough because the English sentence is easy to talk yourself into; the real test is whether every operation the parent promises still makes sense. Most classic inheritance mistakes pass the sentence and fail the operation.
Full entry →