DesignMultipleInheritance

From JQuantLib

Jump to: navigation, search

In this article we demonstrate how multiple inheritance can be implemented easily in Java. Richard Gomes


Sometimes you need that a certain class behave much like two or more base classes. As Java does not provide multiple inheritance, we have to circunvent this restriction somehow.

The solution is very simple but demands some advanced copy and paste technology which can be revamped by something really cool as delegation to an inner class.

The concept consists of:

  • Create an interface intended to expose the public methods of your base class;
  • Make your base class to be a default implementation of your new interface;
  • Supposing you have an application class that should use multiple inheritance somehow, make it implement your new instance as well;
  • Using the delegation pattern, make your application class implement your new interface.


You will have to repeat basically the same code relative to the delegation pattern on all your application classes which implement your new interface. You can see an example at


RichardGomes 00:22, 11 March 2008 (UTC)