Association vs. Aggregation

maks picture maks · Nov 28, 2010 · Viewed 34.1k times · Source

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.

Answer

pohchen picture pohchen · Mar 22, 2011

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