Composition or aggregation: one question settles it
transcript
An interviewer points at the diamond on your diagram. Composition or aggregation? You have five seconds. Filled or hollow? You need a reason, not a guess.
Here is the question that settles it. Who creates the part? And can it outlive the whole?
A book creates its copies in its constructor. A copy has no life without its book. That is composition. Filled diamond, on the whole, the book.
The library holds members. But it never creates them. A member can join another library. Lives on without this one. That is aggregation. Hollow diamond, on the library. In code: made inside the class is composition. Passed in from outside is aggregation, or a plain association.
But here is the catch. Even UML is vague about what aggregation adds. Many teams just draw a plain association, and you will rarely lose the mark.
Who creates the part, and can it outlive the whole? That settles it.
Full breakdown in the lecture.