Inheritance is evil? Maybe.

C++, C#, Java, PHP, ect...
Post Reply
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Inheritance is evil? Maybe.

Post by Jackolantern »

Ok, while I am going to go on record as saying I don't 100% agree with the author of this article, I will say he makes a lot of sense. In many ways classical inheritance causes more problems than it fixes. It polarizes behaviors and makes them choose a certain "path" through your class hierarchy to exist in. Multiple-inheritance is just ugly and causes way more problems than it fixes to be worth it, but since the only popular language that supports it is C++, it isn't a big part of the discussion. Interfaces are somewhat of a nice solution, but again they un-do a lot of what inheritance was supposed to fix: they cause you to re-write lots of code with only small tweaks. "Has-a" inheritance can fix a lot of these problems if the author organizes their classes (and the application as a whole) well, since heavy "has-a" inheritance can quickly make your application get out of control as you begin to forget what classes such-and-such behavior was designed for, or if behavior classes begin to be written too specifically.

Anyway, I guess I am rambling, but check out the article. The author wrote the source in, and largely discusses ActionScript 3.0, but it really is applicable to anything from PHP to C# to Java to Delphi.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Inheritance is evil? Maybe.

Post by hallsofvallhalla »

thanks for the article, as soon as I get a chance I will read it but before I read I want to say I have never been a fan of inheritance. The time saved vs the readability never added up for me.
Post Reply

Return to “Coding”