Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between association and aggregation

Tags:

oop

uml

I understand the difference between aggregation and composition but I am struggling a bit with association. My current understanding is that an association exists between classes when ‘they use each other’, for example, one object is passed to the other during a method call. See also:

http://www.codeproject.com/Articles/330447/Understanding-Association-Aggregation-and-Composit

Both objects exist independently and, in contrast to aggregation, no object is a container class of the other. Does this mean that both objects MUST have a copy of the other(s) (e.g. 1:m relationship) or how else is the association ‘stored’. Any feedback would be very much appreciated.

like image 211
cs0815 Avatar asked Oct 24 '12 07:10

cs0815


4 Answers

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:

  1. Dependency from A to B means that A uses B but indirectly (say by receiving instances of it and forwarding them to other objects).
  2. Association from A to B means that A uses B directly, (for example by calling methods)
  3. Aggregation from A to B means that B is part of A (semantically) but B can be shared and if A is deleted, B is not deleted. Note that this says nothing about how the "is part" is implemented.
  4. Composition from A to B is like Aggregation, where B cannot be shared and if A is deleted, all of its aggregates (Bs) are deleted also.
like image 133
vainolo Avatar answered Sep 30 '22 00:09

vainolo


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.

like image 34
Rahul Tripathi Avatar answered Sep 29 '22 22:09

Rahul Tripathi


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.

like image 23
NullPoiиteя Avatar answered Sep 29 '22 23:09

NullPoiиteя


Aggregation

Let's set the terms. The Aggregation is a metaterm in the UML standard, and means BOTH composition and shared aggregation, simply named shared. Too often it is named incorrectly "aggregation". It is BAD, for composition is an aggregation, too. As I understand, you meant you understand "shared aggregation and composition".

From UML standard:

Precise semantics of shared aggregation varies by application area and modeler.

I haven't found a word about that aggregation supposed multiplicity, for example.

Association.

A definition from UML 3.4.1 standard:

An association describes a set of tuples whose values refer to typed instances. An instance of an association is called a link. 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.

Aggregated relationship is a subclass of Association.

Association is based on relationship. IT is the glue for models.

But your feelings didn't lie - as the shared aggregation is not strictly defined, there is also NO any strictly defined boundary between Association and Aggregated association. Authors of tools and modellers have to set it themselves.

like image 22
Gangnus Avatar answered Sep 29 '22 22:09

Gangnus