File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Inheritence vs  Delegation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Inheritence vs  Delegation" Watch "Inheritence vs  Delegation" New topic
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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Inheritence vs Delegation
 
Similar Threads
Delegation
regarding Delegation
Inheritence
inheritence
JWebUnit