Saturday, September 21, 2013

Aggregation Vs Composition - OOD Concept

I have a very basic example to understand aggregation / composition.

And over a time, thinking about from somewhere I have found a very profound example to explain both concept.

Composition - A composition in which objects forms an entity and that entity cant remain complete if one of the object is removed.

Example : To understand composition, think of a medicinal tablet, which might be made of many elements in various proposition but you cant remove one easily and if you remove one it's wont be same tablet / medicine anymore.

Aggregation - A collection of objects which are loosely connected and can be easily replaces / removed and can be used separately and can be modified easily.

Example : There can be many but I think a car is best one ! One can modify anything in car / replace objects. One can change tire / change color, change wipers / even change engines. And still car will work ! And everything is so loosely coupled that it can be changed easily.

No comments: