| Author |
Inheritence vs Delegation
|
Hamsagayathri Palanisamy
Ranch Hand
Joined: Mar 10, 2008
Posts: 44
|
|
Hi All, can anyone please say me the difference between the inheritence and delegation in java? Thanks in Advance. -Thanks & Regards, Hamsa
|
 |
Marco Ehrentreich
best scout
Bartender
Joined: Mar 07, 2007
Posts: 1220
|
|
Hi Hamsagayathri, inheritance and delegation are both ways to add some functionality to a class. The major difference is that your class is more tightly coupled to a base class if you use inheritance. Then your extending class belongs to the class hierarchy forever. This can be good or not so good depending on the situation. Delegation means that your class is just using the functionality of one or more other classes to provide this functionality for its client classes. Therefore it delegates all work that isn't directly part of your class to other classes. The big advantage is that you can exchange the classes you are delegating to at runtime for example to provide different implementations of the delegation classes. I hope now it's more or less clearer Marco
|
 |
 |
|
|
subject: Inheritence vs Delegation
|
|
|