Inheritance, I am Done With You
February 23rd, 2009
I'm so tired of running into issues with inheritance. I avoid it like the plague, but unfortunately I have to deal with it in some of the code I work with. Tonight is the night that I lower my tolerance level for inheritance.
I used to think deep inheritance was the only issue. Tonight I was trying to refactor a controller class, but every time I changed something a bunch of other controllers would break. I can handle this for a little while, but this is really starting to get annoying. One level of inheritance still causing pain. The final straw was when I tried to add a before filter to the to controller and all my show methods in the other controllers quit working.
Now I'm off to convince the rest of the team to lower their tolerance levels. We all knows it's bad, but we need to stop drinking a case a day.
3 Responses to “Inheritance, I am Done With You”
Sorry, comments are closed for this article.
February 24th, 2009 at 01:31 AM
The problem is not with inheritance, it is with the way that you use (or abuse) it. I have used inheritance for years without experiencing the problem you describe (or any other problems for that matter).
If you also have problems with encapsulation and polymorphism I would suggest that OO is not for you.
February 24th, 2009 at 07:36 AM
So I was a little frustrated when I wrote this last night. I don't put inheritance out completely. I think that it is great in certain areas, and should only be used when there is some deeper commonality between the classes. At the same time I rarely find a case when composition isn't a better option. It make take a little more work, but in the long run it is almost always more maintainable.
My real point to the article is that I need to lower my tolerance for code that "just works." It just took a bad case of inheritance(that I didn't write, btw) for me to say enough is enough.
March 1st, 2009 at 05:28 AM
Just because one programmer's usage of inheritance is bad does not mean that EVERY usage of inheritance is bad. It just proves the point that bad programmers can screw up in any language and any paradigm.
My own impementation of OOP has been criticised by many for being "wrong" when in fact it is merely "different". My development times are short, my code is maintainable, yet I use inheritance extensively and object composition never.
It's not the tools, its the worker that gets results.