Win a copy of Fixing your Scrum this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

regarding Delegation

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to know the concept of Delegation in Java. I like to know the difference between Inheritance and Delegation and their pros and cons.

Thanks in advance
 
Ranch Hand
Posts: 399
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sai,

The gerneral meaning of Delgate is to pass on or hand on. In programming terms, you want to use the existing code without any modification. You can find a very good explanation in the following link:

web page

Advantage of Delegation is code reuse, achieve multiple inheritence

The concept of Inheritence is that you gain the features of the base class to the subclass using extends keyword. You cannot inherit from more than one base class.

Hope that helps..

Thanks and Regards

Ayub
[ August 10, 2006: Message edited by: Ayub ali khan ]
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With delegation part of your behavior is implemented by a seperate object instance while using inheritance there is only a single object instance. With delegation you can have the SELF problem where if you do something you can not pass any references to 'this' because this inside the delegate is different from 'this' of the delegating object. Problem does not exist with inheritance.

With inheritance, every interface of the parent object is inherited to the child object which is unfortunate. With delegation, the delegating object only exposes the interfaces it chooses to expose regardless of what the delegate implements.
 
reply
    Bookmark Topic Watch Topic
  • New Topic