Aggregation versus Composition

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
Line 2: Line 2:
 
Wikipedia provides us the university example to illustrate the difference between aggregation and composition.
 
Wikipedia provides us the university example to illustrate the difference between aggregation and composition.
  
 +
''Association'' (represented by a solid line, with an arrow if unidirectional) occurs when one object instance causes another to perform an action on its behalf. Associations are typically implemented by references.
  
'''Composition''' (represented by the solid diamond) occurs inside objects when the relationship is such that if the super-object is destroyed the sub-object also ceases to exist. In this example if the university is closed the departments also close.
+
'''Composition''' (represented by the solid diamond) occurs inside objects when the relationship is such that if the super-object is destroyed the sub-object also ceases to exist. A Composition adds a lifetime responsibility to Aggregation. In this example, if the university is closed the departments also close.
  
'''Aggregation''' (represented by the hollow diamond) occurs in the case where the destruction of one object does not end the existence of the other. When the university closes the professors continue to exist.
+
'''Aggregation''' (represented by the hollow diamond) occurs in the case where the destruction of one object does not end the existence of the other. An Aggregation is an Association which denotes an "is part of" relationship. In this example, when the university closes the professors continue to exist.

Revision as of 10:31, 4 October 2008

Aggregation versus Composition

Wikipedia provides us the university example to illustrate the difference between aggregation and composition.

Association (represented by a solid line, with an arrow if unidirectional) occurs when one object instance causes another to perform an action on its behalf. Associations are typically implemented by references.

Composition (represented by the solid diamond) occurs inside objects when the relationship is such that if the super-object is destroyed the sub-object also ceases to exist. A Composition adds a lifetime responsibility to Aggregation. In this example, if the university is closed the departments also close.

Aggregation (represented by the hollow diamond) occurs in the case where the destruction of one object does not end the existence of the other. An Aggregation is an Association which denotes an "is part of" relationship. In this example, when the university closes the professors continue to exist.

Personal tools