Relation Between Classes

There are mainly three type of relation exist in between classes.

  1. Association.
  2. Aggregation.
  3. Compostion.

Association is a (*a*) relationship between two classes. It allows one object instance to cause another to perform an action on its behalf. In nut shell if there is any relation between two classes means there are Associative with each other or in other words There is an Association in between classes.

Aggregation describes a special type of an association. Aggregation is the (*the*) relationship between two classes. When object of one class has an (*has*) object of another, if second is a part of first (containment relationship) then we called that there is an aggregation between two classes. Aggregation always insists a direction.

Aggregation means HAS-A

"In one line when one class contain the object of other class then this type of relation is known as Aggregation"

"Tree aggregate Leaf "
Public class Leaf
{}
Public class Tree
{Leaf _lf =new Leaf () ;}

Composition means Part-OF relation, two entities interdependent with each other.

e.g. Hearts and Human relation. A heart can't exist without a human being and vice versa any human can't exist without heart.

So in summary, we can say that aggregation is a special kind of an association and composition is a special kind of an aggregation. (Association->Aggregation->Composition

Ebook Download
View all

OOP/OOD

Read by 0 people
Download Now!
Learn
View all