Inheritance is evil? Maybe.
Posted: Mon Aug 16, 2010 12:16 am
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.
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.