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.
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.
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.
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.
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.
There are four kinds of Class relationships
Man
uses a Class Pen
( Pen is still there when man die )Man
has a Class Car
( Car is still there when Man die )Man
owns a Class Heart
( When Man die, Heart die )Man
is a Class Human
( Man is a Human )A relationship between classes of objects
Inheritance>Composition>Aggregation>Association
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With