Java Multiple Inheritance Rant

I know, I know, it’s a tired old subject. But when you’ve got to work with a crippled language like Java, sometimes tired old subjects rear their ugly heads again, and you need to rant a little.

Here’s a very simple, very concrete example of why Java’s policy not to include multiple inheritance in the language sucks donkey balls, and the “we use interfaces instead of multiple inheritance” excuse shows how lame it is:

  1. You’re using a framework1 that defines a class A and a class B derived from A.
  2. You’re using both A and B in your project. The framework forces you to subclass either class in order to use it. Let’s call those derivates A’ and B’, because I quite like that notation.
  3. You need to extend the functionality of A in your project for all derivates of the class.

In Java, you’re forced to put this functionality into both A’ and B’, even though duplicate code is a code smell.

Oh, sure, you can factor the functionality out into a class C that you use in A’ and B’ in an identical manner, but that doesn’t really avoid duplicate code, it just reduces it. And your class C is guaranteed to have an ugly interface. And it’ll be a real hoot accessing members of the classes you’re extending without making all sorts of shit public. Or, worse still, adding more layers of indirection.

Fuck you, Java.

  1. Aren’t you always using frameworks in Java? []