Q&A Categories

  • No categories

Aggregation vs Composition

Aug

23

2012

What is the difference between Aggregation and Composition ?

In: Uncategorized Asked By: oop
+3
0
vote
Answer #1

In OOP Composition reffers to the relationship between classes of type “A” let’s say containing refferences to other classes of type “B”. The second condition is that type “B” instances cannot exist without the type “A” instances.
For example a class of type “A” can be a Car and a class of type “B” can be a Wheel. Destoying the Car would also destroy the enclosed Wheel.

On a complementary look, is the Aggregation, which needs the same first condition – classes of type “A” containing refferences to other classes of type “C”, but the econd conditon says the opposite: instances of type “C” can continue to exist without the instances of type “A”.
The perfect example here, additionaly to the one above is to consider the class of type “C” as being the Driver of the Car. Destroying the Car object one will not expect that the Driver should also be destroyed, since the Driver can move to another Car or Vehicle for instance.

Answers Answered By: alo [ Grey Star Level]

Answer this Question

Enter name & email to post an Answer. You can also Login / Join us

For a better management of this site please consider Logging in / Joining us before posting a Question. It makes everithing easier for us.

Please enter the captcha code bellow.
Logged in users don't have to use captchas. Don't have an account? Join us!

 

Link Exchange:

You can add url to the best of the internet directory. Our url is added under Reference Directory
HE Blog Directory WEB LOG SHOWWEB LOG SHOW