DesignObservablePattern

From JQuantLib

Jump to: navigation, search

In this article we present an alternative implementation of Observer and Observable classes which addresses major difficulties imposed by standard Java runtime implementation. Richard Gomes


Complex applications may require complex object models, involving multiple inheritance and eventually the well known Observable Pattern. In this situation a difficulty arises because Observable is a class and not an interface. It's a problem because any class which needs to extend Observable becomes immediately prohibited of extending any other class as Java does not allow multiple inheritance.

One possible solution is providing multiple inheritance as explained in the article |Designing Multiple Inheritance. This is not convenient because being observable is rarely the main behavior a class should have.

The solution for this problem could not be any other unless: implement Observable as an interface, instead of a class. You can see our reimplementation of the Observable/Observer pattern at

In order to make it easy the way an Observable works, we provide a default implementation for it. Please see

You can also see how a DefaultObserver is used at


Richard Gomes 00:23, 11 March 2008 (UTC)