June 12, 2009

Inheritance vs Aggregation vs Composition


Inheritance - "Is A" Strongest Relationship

We depend on the functionalities of a Super Class

Aggregation - "Has A / Is Part Of" - Weaker Relationship

As shown in the example Aggregation occurs when the part of outlives the whole. e.g the listener instance could be alive even after WebServer instance is garbage collected


Aggregation Example ("has a"):



Composition - "Uses A" - Stronger Relationship

In a composition relationship the listener instance lifespan lasts till the WebServer instance is garbage collected.


Composition Example ("uses a"):







No comments: