Assosiation : Aggergation vs Composition

2 views
Skip to first unread message

Rajnish

unread,
Nov 27, 2008, 11:01:19 AM11/27/08
to Technical Discussion
Association: Aggregation vs. Composition
-----------------------------------------------------------------------------------------
When we say one thing depends on other, then more or less they are
associated.

If we say Batsman has Batting Skills, then it is an association and
they have "has - a" relationship.

Aggregation vs. Composition
-----------------------------------------------------
You may have heard Aggregation is a weaker relationship and
Composition is a strong relationship, but the point is how to express
both in UML and more is how to reflect it in your code.

In UML
------------------------
Composition: By a filled diamond box
Aggregation: By a empty diamond box


Suppose there are two classes: class A and class B
--------------------------------------------------------------------------------------
Composition in Coding: (C++)
---------------------------------------------------
class A{
B obj_B;
}

Aggregation in Coding: (C++)
---------------------------------------------------
class A{
B * obj_B;
}


Composition in Coding: (JAVA)
---------------------------------------------------
class A{
B obj_B;
}

Aggregation in Coding: (JAVA)
---------------------------------------------------
Instead of keeping object of class B in A, keep interfaces in A as
under:

Interface IB{
}

class B implements IB{
}

class A{
IB obj_B;
}

----------------------------------------------------------------------------------------------
These were the briefings from a seminar of UML and OOPS
You can add you onw experiences in the same:
--------------------------------------------------------------------------------------------


-
Regards
Rajnish Kamboj
Reply all
Reply to author
Forward
0 new messages