I know, somebody had asked the same question about this case, but i still don\'t really get it, i need a specific answer. Thank you :D
Since Gangnus did not correctly explain the meaning of composition, I'll have to do it.
As explained by Gangnus, an aggregation is a special form of association with the intended meaning of a part-whole-relationship, but without a precise semantics (the UML spec says: "Precise semantics of shared aggregation varies by application area and modeler"). For instance, we can model an aggregation between the classes Car
and Engine
and between the classes Course
and Lecture
since an engine is part of a car and a lecture is part of a course.
A composition (also called "composite aggregation" in the UML spec) is a special form of aggregation, where a component instance is part of at most one aggregate instance at a time (that is, it cannot be shared between several aggregates). This means that the aggregation between Car
and Engine
is a composition (because an engine cannot be shared between two cars at the same time), while an aggregation between Course
and Lecture
is not necessarily a composition since a lecture can be shared among two courses (e.g. a database management course and a software engineering course could share a lecture on UML). This implies that the multiplicity of a composition's association end at the aggregate side is either 1
or 0..1
, while it may be also *
in the case of a non-composite aggregation.
In addition to this main characteristics of a composition (to have exclusive parts), a composition may also come with a life-cycle dependency between an aggregate and its components implying that when an aggregate is deleted, all of its parts are deleted with it. However, this only applies to some cases of composition, and not to others, and it is therefore not a defining characteristic. The UML spec states: "A part may be removed from a composite instance before the composite instance is deleted, and thus not be deleted as part of the composite instance." In our example of the Car
-Engine
composition, it's clearly the case that the engine can be removed from the car before the car is destroyed, in which case the engine is not destroyed and can be re-used.