My Thoughts: ‘Interface’ isn’t harmful

Added to Technology

My thoughts about Object Oriented Programming have evolved over the years. Especially in the past 6 months. My development of MicroObjects has caused a lot of thinking about Object Oriented Programming and how to develop better and more maintainable software.

A lot of great discussions that have certainly helped drive the MicroObject concept to where it is now.

One of the practices in Object Oriented Programming is Composition over Inheritance. I don’t see the emphasis a lot in discussions or what I read. Maybe I’m not reading enough, or seeing enough. I try to default to “Why am I wrong?” when I have an idea. I totally accept this as a possibility. I appreciate any efforts to demonstrate my wrongness. 🙂

Being a big fan of Composition over Inheritance, I feel the need to bring up a question from a blog post I stumbled on recently.

‘Interface’ Considered Harmful

I don’t really agree with the author on interfaces being harmful; but I’ve also worked most of my career in interface capable langauges. I’m probably leaning a bit towards what I’m comfortable with.

I’ve done some C++ and faked interfaces with abstract classes; I find value in a mechanic that limits the interface to just a contract. Java goes a little overboard with their interfaces allowing too much inside of them. I like C#’s contract only form. Which is totally violated in C# 8’s “Default Interface Implementations”. If you need a default implementation – it’s a damn abstract class. This might get around the point of the article that you can’t inherit multiple implementations; at least a little.

Either way – I’m not a fan of this. I expect it’s due to my desire to use MicroObjects. 🙂


What actually prompted me to do this little write up is where the failing of not being able to use multiple inheritance is highlighted.

public class Subject {
    private List<Observer> observers = new ArrayList<>();
    private void register(Observer o) {
        observers.add(o);
    }
    private void notify() {
        for (Observer o : observers)
            o.update();
    }
}

public class MyWidget {...}

public class MyObservableWidget extends MyWidget, Subject {
    ...
}

I look at MyObservableWidget and see an object that is a relationship. I look at this and think it should be implemented as


public class Subject implements ISubject{...}

public class MyWidget implements IWidget{...}

public class ObservableWidget implements IWidget, ISubject{
    private final IWidget _widget;
    private final ISubject _subject;
    public ObservableWidget(IWidget widget, ISubject subject){...}
    ...
}

We encapsulate the relationship between IWidget and ISubject in an object. Doing this as a generic class allows it to work for any implementation of IWidget and ISubject. Not just making an ObservableMyWidget class for the specific MyWidget and Subject.
While I’m not looking to pull out re-usability; I look for good object oriented design and if I can tweak it for wider usability; I’ll do so. In this instance, our ObservableWidget is an example of that. It will work for any IWidget ISubject combination.

The author specifically addresses the idea of having

public class MyObservableWidget extends MyWidget

hold a reference of Subject.

Well then have MyObservableWidget hold a reference to Subject and delegate to it?

What? And duplicate the delegation code in every one of my observers? How crass. How degenerate. Ugh.

I agree that doing so is undesirable. It’s crass, but I think so for a different reason. Our ObservableWidget IS both a widget and observable. It SHOULD be treatable as both.
Holding a reference to the observable, we can’t. We don’t expose the contract of observability. Our consumers MUST know our type; we become tightly coupled.

With the ObservableWidget implementing only interfaces, we don’t have to duplicate code. If it tightly coupled itself to MyWidget and Subject then it would end up duplicating for every observed class, which is what the objection seems to be. Using only interfaces We don’t tightly couple ourselves to concrete implementations. Having the widget and observer as collaborators; we use composition, over inheritance, to encapsulate the behavior of a relationship.


I see encapsulating the relationship as a stronger design than the tight coupling of implementation. interface keyword or multiple inheritance – this is the design I prefer.

I don’t think the interface keyword is harmful. I think it’s a restriction which forces a different way of thinking. It’s our behavioral contract. There’s no assumption or possible implementation (curse you C# 8) associated with it. No data expectations possible.

I’m advocating for a relationship to be represented by a new object who’s single responsibility is knowing how the collaborators interact. That’s what I’ve shown here. This is an alternative to either violating the separation of concerns or duplication of code.

About the Author


Quinn got hooked on programming in a computer introduction course. For over 20 years, he's never gone more than a couple months without programming something; even while getting a degree in physics. Quinn has always been looking for ways to improve the code he writes, and the code of fellow developers. After being introduced to FAST Agile (http://www.fast-agile.com/), TDD, and XP practices - he's become a vocal advocate for their adoption.

After an opportunity to learn from Object Oriented Programming from Fred George, Quinn has taken these practices to heart. His blog (https://QuinnGil.com) exists to record his experimentation of Object Oriented Programming. Less than a year after glomming onto actual Object Oriented Programming, Quinn coined "MicroObjects" (https://QuinnGil.com/uobjects/) as a development style to produce highly maintainable code, quickly, with a low defect rate.

You can find Quinn in front of his computer via twitter @TheQuinnGil or quinn@quinngil.com.


This is an Agile Alliance community blog post. Opinions represented are personal and belong solely to the author. They do not represent opinion or policy of Agile Alliance.

Agile2023 Registration

Stay Up-to-Date!

Get updates on Agile events, programs, and more by subscribing to the Agile Alliance Newsletter.

Agile MiniCon Basics

Recent Posts

BYOC Member Lean Coffee