difference between association and aggregation
From the UML Superstructure 2.4.1:
An association declares that there can be links between instances of the associated types. A link is a tuple with one value for each end of the association, where each value is an instance of the type of the end. (UML Superstructure, Page 37)
Nothing more, nothing less. and very vague. Because of this, it is also very hard to understand. What I defined (In a course I teach) is a hierarchy of links from dependency to composition where:
- Dependency from
A
toB
means thatA
usesB
but indirectly (say by receiving instances of it and forwarding them to other objects). - Association from
A
toB
means thatA
usesB
directly, (for example by calling methods) - Aggregation from
A
toB
means thatB
is part ofA
(semantically) butB
can be shared and ifA
is deleted,B
is not deleted. Note that this says nothing about how the "is part" is implemented. - Composition from
A
toB
is like Aggregation, whereB
cannot be shared and ifA
is deleted, all of its aggregates (B
s) are deleted also.
Aggregation is an Association relationship where the Association can be considered the containing class 'Owning' the contained class, and the lifetime of that relationship is not defined.
Association is an 'Has-A' relationship.
Example:-
public class Person
{
private final Name name;
private Address currentAddress;
//...
}
In this case, the Person Has-A name and Has-A Address, so there is an Association between Person and Name, and Person and Address.
An association describes a relationship between instances of one or more classes. In the words of the UML Reference Manual, "Associations are the glue that holds together a system."
Aggregation is a form of association in which there is a "whole-part" relationship. You may say that if a class Airplane has a class Engine then this forms a "whole-part" relationship.