People Are Killing Off Inheritance

by Jon Davis 7. January 2009 11:56

I'm noticing that, more and more lately, people are throwing out inheritance, as is demonstrated by this StackOverflow thread.

I'm still trying to concede my opinion on this. If the proponents of this attitude did not have "use delegation" up their sleeves I would say they are all either nuts or completely clueless about how good OOP can be written.

I think inheritance is a fabulous thing and in well-designed systems is even more important than interfaces, particularly in fundamental, framework scenarios like visual/UI controls, ORM, I/O base classes, and the like. It's also great for application design--three different account types, for example, each with a different subset of behavior but all sharing a lot of commonalities (all being accounts).

I imagine, however, that most of these folks have experienced the real world in team environments wherein bad OOP implementations of inheritence have resulted in unmaintainable code. In such cases, I can certainly see how interfaces, as a compromise, forces team members to stick to the testable specs rather than futz with the legacy. I most definitely cannot fathom how such environments are productive; reimplementing interface behavior everywhere just sounds atrociously bogged down, nothing gets done in such environments.

Delegation as an alternative to inheritance, however, makes sense in the area of code reuse. Compositing behavior services and providers in a composite class that implements multiple interfaces and hands off the implementations of those interfaces' members to the composite members is a great way to reuse code, should inheritence be avoided. 

A sealed composite delegation class does not, however, support is-a relationships, only behaves-like-a relationships via interfaces. Using interfaces alone, we again go back to procedural code and lose the great benefits of OOP and replace it with OBP (objects-based programming), a la COM. VB6 supported polymorphism as such, and its value stopped there. I have hardly used VB6 since C#, the true OOP language, became available to me as a Microsoft tools user.

Actually, a good persuasive article lies over here in favor of composition / decorator patterns. It's so persuasive, actually, that I personally think the C# 4.0 team should consider making composition / decorator pattern as easy to implement as inheritance.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Software Development


Add comment

(Will show your Gravatar icon)  

  Country flag

  • Comment
  • Preview


Powered by BlogEngine.NET
Theme by Mads Kristensen

About the author

Jon Davis (aka "stimpy77") has been a programmer, developer, and consultant for web and Windows software solutions professionally since 1997, with experience ranging from OS and hardware support to DHTML programming to IIS/ASP web apps to Java network programming to Visual Basic applications to C# desktop apps.
Software in all forms is also his sole hobby, whether playing PC games or tinkering with programming them. "I was playing Defender on the Commodore 64," he reminisces, "when I decided at the age of 12 or so that I want to be a computer programmer when I grow up."

Jon was previously employed as a senior .NET developer at a very well-known Internet services company whom you're more likely than not to have directly done business with. However, this blog and all of have no affiliation with, and are not representative of, his former employer in any way.

Contact Me 

Tag cloud


<<  June 2021  >>

View posts in large calendar