JDK-4687908 : Create an Observable interface
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • Submitted: 2002-05-20
  • Updated: 2016-04-20
  • Resolved: 2016-04-20
Related Reports
Relates :  
Description

Name: rmT116609			Date: 05/20/2002


FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195], with Service Pack 2

A DESCRIPTION OF THE PROBLEM :
The java.util.Observable class would be much improved if its methods were declared in an interface. Since Java only supports single inheritance, it is impossible to write a class that extends some other class *and* is also Observable.

Here is what I'm proposing:

Create an "observable interface" that Observable implements:

public interface IObservable {
   << all current Observable method>>
}

public class Observable implements IObservable {
  << same implementation as today >>
}

Now, I can write a class that extends another class *and* is also an IObservable (by using a concrete Observable as an instance field):

class MyClass Extends MyOtherClass implements IObservable {
   private Observable obs = new Observable();

   << Delegate all IObservable methods
      to the obs object. >>
}

This would be a very simple change to the API but would make Observables much more flexible.

(Review ID: 146748) 
======================================================================

Comments
In retrospect, it would have been better for Observable to have been an interface. It was probably made a class in order to share implementation of the list of Observers and the notification dispatching mechanism. However, Observer and Observable will be deprecated. See JDK-8154801. Refactoring Observable into an interface is too great a change for these old APIs.
20-04-2016

EVALUATION This could be done in a compatible way but we are hesitant to further evolve this legacy class. ###@###.### 2002-12-18
18-12-2002