• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Disadvantage for the Inheritance

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the Disadvantage for the Inheritance?
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tight coupling. It is very difficult to refactor the code.
[ November 19, 2007: Message edited by: Anil Kumar Saha ]
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anil Kumar Saha:
Tight coupling. It is very difficult to refactor the code.



I am surprised. Indeed, refactoring is no doubt important but that wouldn't become a reason to avoid inheritance. And I don't see how inheritance is difficult to refactor, may be but it depends. Refactoring is a method or a process or an idea through which we refactor our code. We do refactoring to improve the quality of the code, make it simple and easy to read, make it flexible and customizable, avoid unnecessary duplication and tight coupling, make it customizable and easy to maintain.

I would say, avoid inheritance where composition makes a good sense and can serve better. Inheritance, indeed, couples the things tightly and results in difficulty to add new features or to customize and in maintenance issues. Furthermore, it would make the unit testing a problem or sometimes give you false results during testing.

However, its a powerful feature if used appropriately.
 
Anil Kumar Saha
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ansari,
Brilliant elaborate answer. Awesome!!!
But my dear friend,I'm also surprised to see to repet my words in your answer.


Inheritance, indeed, couples the things tightly and results in difficulty to add new features or to customize and in maintenance issues.

 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anil Kumar Saha:
Brilliant elaborate answer. Awesome!!!
But my dear friend,I'm also surprised to see to repet my words in your answer.



Thanks for the compliments pal.

You should not surprise because I used the word indeed, that is clearly emphasizing that I am repeating your words, there is no doubt. Moreover, I am not finding where I have denied this particular bit of your answer in my previous post.
[ November 20, 2007: Message edited by: Adeel Ansari ]
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rex tony:
What is the Disadvantage for the Inheritance?



There is nothing wrong with inheritance itself - however some of the ways in which inheritance is used are less than optimal.

Have a look at Allen Hollub: Why extends is evil

Uses and Abuses of Inheritance, Part 1
Template Method and Strategy: Inheritance vs. Delegation
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use Inheritence then You are redefining the behaviour of class and thus you can guarantee original behaviour of Class any longer.

The Typical example is compared against Interface is how to implement Thread.

Specification says avoid extend Thread but rather use implement Runnable interface because of the fact that by extending Thread Class, Original behaviour is not guaranteed

Observer some other Java rancher agrees with me
https://coderanch.com/t/233016/threads/java/extends-Thread-Vs-Implements-Runnable
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Allen Holub wrote Why Extends is Evil. As usual he's being deliberately provocative, but he makes some good points about the risks in inheritance, and convinced me to be extremely reluctant and careful when it comes to extending concrete classes. Read it and see if you can find two things to agree with and two things to challenge.
 
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic