Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Association vs. Aggregation [duplicate]

Tags:

java

oop

uml

I have reviewed a lot of information about these things, but can't understand what is the difference between them? In Fowler's UML Distilled says that Aggreagation is strictly meaningless, so author recommends not to use it in diagrams. Explain, please, when I should use each of them and how it will influence on java code.

like image 408
maks Avatar asked Nov 28 '10 18:11

maks


People also ask

What is the difference between aggregation and association?

Association refers to "has a" relationship between two classes which use each other. Aggregation refers to "has a"+ relationship between two classes where one contains the collection of other class objects. Inflexible in nature.

What is the difference between association vs aggregation vs composition?

The composition is stronger than Aggregation. In Short, a relationship between two objects is referred to as an association, and an association is known as composition when one object owns another while an association is known as aggregation when one object uses another object.

What are the differences and similarities between aggregation and composition?

Aggregation is one type of association between two objects that is also describing the “have a” relationship. Composition is a specific type of Aggregation which implies ownership. Aggregation is indicated using a straight line with an empty arrowhead at one end.

What is the difference & similarities between aggregation & inheritance?

The difference is typically expressed as the difference between "is a" and "has a". Inheritance, the "is a" relationship, is summed up nicely in the Liskov Substitution Principle. Aggregation, the "has a" relationship, is just that - it shows that the aggregating object has one of the aggregated objects.


1 Answers

There are four kinds of Class relationships

  1. Association: uses a
    Ex:a Class Man uses a Class Pen ( Pen is still there when man die )
  2. Aggregation: has a
    Ex:a Class Man has a Class Car ( Car is still there when Man die )
  3. Composition: owns a
    Ex:a Class Man owns a Class Heart ( When Man die, Heart die )
  4. Inheritance: is a
    Ex:a Class Man is a Class Human ( Man is a Human )

A relationship between classes of objects

Inheritance>Composition>Aggregation>Association

like image 76
pohchen Avatar answered Sep 30 '22 11:09

pohchen