Difference between aggregation and composition
aggregation vs composition:
Aggregation and composition are both words that relate to a sense of ownership. Because of this common factor, some may be downright baffled by the difference between these words whereas for some, the meanings and definitions of these two words may be crystal clear. Therefore, the target of this article is to provide a comprehensive account of what aggregation and composition is and also to shine a light on how they are different from each other.
What is aggregation?
The term aggregation is used to indicate ownership or a whole/part relationship. It is a special case of association where a directional association between objects is indicated. An aggregation indicates a weak-coupled relationship between two entities, where one entity could be part of another, but either can exist without the other, independently. In aggregation, the object exists outside the other, is created outside. For example, one can point out the relationship between a school and a teacher.
What is composition?
Composition too is a form of relationship which is different than the rest. It can be stated as a strong-coupled relationship between two entities, where the one entity is part of another, and both need each other for their existence. In the case of composition, the object only exists, or only makes sense inside the other, as a part of the other. For example, one can take the relationship between a human being and his heart. The human being cannot exist without his heart and the heart does not function wthout the human being.
What is the difference between composition and aggregation?
While both aggregation and composition refers to types of bonds and relationships, the kind of relationships or bonds indicated by the two words are quite different from each other. While aggregation refers to a type of bond where the bond is weak and one object is created outside the other and has no strong, unbreakable relation to it. For example, one can indicate the relationship between a man and his car. And yet, composition refers to a strong relationship between two or more entities where one part is created within the other and they are almost inseparable.
In the case of an aggregation, the entities within that relationship can very well exist without each other. As the objects exist outside of each other, they are not interdependent on each other. For example, one can indicate the relationship between a doctor and a hospital Whereas in the case of a composition, as the objects within the bond are dependant on each other, one object either cannot exist without the other or does not make any sense without the other. The best example for this sort of relationship would be a human being and a heart. Obviously, these two entities, if taken separately cannot exist without each other and does not make any sense independently either.