User:Szucsatti/uml

There are several relations in UML design that seem to mean the same thing. What is then the difference between them ? Here is a good explanation of the differences.

1. Association - basically means that an object can send messages to another object. Sending messages in Java means calling methods. At the level of implementation this is accomplished with the help of a pointer (reference in Java). This may be an instance reference or local reference (like arguments).

public class A{   ..... private B b;   ....

public void doStuff(C c){ .....   } }


 * A| --> |B|


 * A| --> |C|

2. Aggregation - this one is a bit harder to digest, since it's definition is quite lax, so everybody may have it's own interpretation. Basically it means a "is part of" relationship. Aggregations can not be circular. An object can not be part of itself. An object does not have a lifetime responsibility for another object. It only contains a reference to it. The lifetime of the objects are independent from each other. If one is destroyed the aggregated objects still continue to live.

Let me use a very good example found on Wikipedia: a university has many departments, and each department have professors. If a university closes all the departments stop to exist, while the professors will continue to exist. Therefore the university - department is a composition while the department - professor relationship is an aggregation.


 * A| <>-->|B|

3. Composition - is an aggregation where the lifetime of the part is controlled by the whole.


 * A| <#>->|B|