Geeks With Blogs


Google My Blog

Murray Gordon Flash a-ah! Savior of the universe...

Here’s few words on Interfaces and Inheritance from Doug Turnure.

Deciding between Interfaces and Inheritance

So often, I talk to developers who know how to do interfaces and inheritance in .NET, yet don't seem to have consistent rules around when to use which.

It's been my experience that when you get into the trenches with developers, there is a huge disconnect between the theoretical tenets of OO (encapsulation, abstraction, polymorphism, and inheritance) and the day to day coding of applications. Developers can usually spout definitions for each of these concepts, but when you ask them to point out where they do this in code, there is often confusion. Furthermore, if you try to ask a developer whether an interface or base class is best suited for a particular boundary, the answers can be all over the map.

There really is a reason to choose one over the other. If you want to hear the bloody details, come to the talk. If not, the quick and rough answer is this: Interfaces are better for those places where extensibility is the highest requirement. Inheritance is better for those places where reusability is the highest requirement.

You can screw up your software by doing too much of either one, or by neglecting either one. I've heard people say that inheritance is bad. If misapplied, I agree. However, inheritance is very good when applied properly. Can you imagine how much code you would need to write to display a simple Winforms window, if you couldn't inherit from the base class?

On the other hand, the corporate graveyards of America are littered with the bytes of non-extensible software, where interfaces could have easily saved the day.

There is much to be said for understanding how to balance the use of interfaces and inheritance. After the talk, I'll post the slides here.

Posted on Tuesday, September 20, 2005 2:07 AM | Back to top

Comments on this post: Doug Turnure on Deciding between Interfaces and Inheritance

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Murray Gordon | Powered by: