Composition vs. Aggregation


Instance A keeps instance B as a member. B’s only purpose and capability is to serve for A. It’s irrelevant in any other context. B was probably created because A had become too complex and trying solve too any problems.


Instance A keeps instance B as a member again. But B could serve its purpose in another class as well.

Why would the differentiation matter?

For many thing it could matter. One thing I just notice having the distinction in mind would be useful is that: If A and B has composition relationship and you want to have Unit Tests for A, you don’t have to isolate B.
Why? [I will write it later.]

Notify of
Inline Feedbacks
View all comments