Link Details

It's so much easier than programming. Login and vote now.
Link 105271 thumbnail
User 185351 avatar

By jsugrue
via java.dzone.com
Published: Aug 20 2008 / 14:08

Is inheritance really useful or is it a feature that causes more problems than it solves? Certainly I can't think of a case where I've been really grateful that I've been able to inherit from a superclass but I can think of several instances where it has caused friction and where the extension mechanism of inheritance tended to lead the programmer the wrong way.
  • 7
  • 10
  • 590
  • 185

Comments

Add your comment
User 202710 avatar

wytten replied ago:

1 votes Vote down Vote up Reply

"Rectangle extends Square?" I think my head just exploded...

User 282119 avatar

Rob Signorelli replied ago:

1 votes Vote down Vote up Reply

Inheritance is a tool. Like ANY tool, you can use the tool in the wrong place or use the the right tool in the right place improperly. That's not a fault of the tool. It's the fault of the one holding it.

Overusing it in place of composition can lead to poor, inflexible implementations. Underusing it can lead to incredibly complex solutions that were wayyy over-engineered to solve the given problem, making future maintenance a nightmare. The author made an argument for why inheritance might not be the best approach in ONE abstract case. To believe that this is a reason to dismiss inheritance altogether is just silly.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.