• Post Reply Bookmark Topic Watch Topic
  • New Topic

Delegation vs Inheritance  RSS feed

 
Lovish Setia
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain me the difference between Delegation and inheritance?
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you think the difference is? What have you been told?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a high level, the difference would be exposing some functionality via an internal call to a different entity vs providing some functionality which has been inherited from the parent entity. Does that help answer your question?
 
Vineeth Menon
Ranch Hand
Posts: 79
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lovish,

Delegation is Design Pattern in Java where you have a object delegating it's task to another helper object. Check out this link in Wikipedia you might a rough idea on what delegation is.

Inheritance is getting the the process where one object acquires the properties of another, with the use of inheritance the data is made manageable in a hierarchical order.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vineeth Menon wrote:..with the use of inheritance the data is made manageable in a hierarchical order.

Maybe you are confusing encapsulation with inheritance? Inheritance has got nothing to do with "making the data manageable"
 
Vineeth Menon
Ranch Hand
Posts: 79
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:
Vineeth Menon wrote:..with the use of inheritance the data is made manageable in a hierarchical order.

Maybe you are confusing encapsulation with inheritance? Inheritance has got nothing to do with "making the data manageable"


Hey Maneesh,

I was thinking on these lines


and that is why I said data in a manageable in a hierarchical order.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lovish Setia wrote:Please explain me the difference between Delegation and inheritance?

When trying to work out a lot of these terms, it's often worth consulting a dictionary.

Unfortunately, that advice falls down slightly when it comes to "inheritance", because it has a very specific meaning in OO languages - but basically, it means subclassing.

"Delegation", on the other hand, is very similar to its dictionary meaning.
What is "delegation"? It's getting someone else to do what you want.

Well, it's exactly the same in Java, except that you get another object to do what you want - usually one that is contained in the 'delegator', but not always.

Winston
 
Lovish Setia
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to everyone for their replies.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
When trying to work out a lot of these terms, it's often worth consulting a dictionary.


Or a Google search.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vineeth Menon wrote:
I was thinking on these lines


and that is why I said data in a manageable in a hierarchical order.


It's not clear from that why you chose inheritance here, or how you plan to take advantage of it, but I will point out that inheritance is primarily about specializing behavior, not about data.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lovish Setia wrote:Please explain me the difference between Delegation and inheritance?


In the future, please SearchFirst(←click). Thanks!

http://www.google.com/search?q=difference+between+Delegation+and+inheritance
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
Winston Gutkowski wrote:
When trying to work out a lot of these terms, it's often worth consulting a dictionary.


Or a Google search.


I agree with Jeff. Someone once told me that English dictionary meanings of words might not relate exactly when it comes to Java concepts.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:I agree with Jeff. Someone once told me that English dictionary meanings of words might not relate exactly when it comes to Java concepts.

First: these aren't Java concepts, they're OO concepts.

Second: The terms didn't come from nowhere, and we communicate through language. With a few exceptions, the terms you'll run into have some basis in the real world, so it's worth knowing what they mean in general before you start to delve into all the intricacies of what they mean in Object-Oriented programming. Probably doubly so if your first language is not English.

Winston
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
Mansukhdeep Thind wrote:I agree with Jeff. Someone once told me that English dictionary meanings of words might not relate exactly when it comes to Java concepts.

First: these aren't Java concepts, they're OO concepts.

Second: The terms didn't come from nowhere, and we communicate through language. With a few exceptions, the terms you'll run into have some basis in the real world, so it's worth knowing what they mean in general before you start to delve into all the intricacies of what they mean in Object-Oriented programming. Probably doubly so if your first language is not English.

Winston


Indeed. In another thread. When somebody asked about abstraction and polymorphism, a response merely suggested looking those terms up in a dictionary. I pointed out that simply knowing the general English definitions wouldn't tell one much about what they mean in an OO or Java context. I still maintain that that is true, BUT I didn't mean that knowing the general English terms had no value.

I do think it's helpful to know the general definitions as well, to close the loop. It's just not particularly useful as a sole source of definition for a newcomer.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well , I can't really argue on any of those fronts now, can I? You guys are better than me at both Java and English.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!