[4970] in java-interest

home help back first fref pref prev next nref lref last post

Re: Observable problems

daemon@ATHENA.MIT.EDU (David Geary)
Wed Jan 24 19:52:59 1996

Date: Wed, 24 Jan 1996 16:22:50 -0700
From: David.Geary@Central.Sun.COM (David Geary)
To: chris@telesph.com
Cc: java-interest@java.Eng.Sun.COM

  Just thank the good Lord that we don't have to deal with the complexities 
of multiple inheritance, otherwise you'd have to do:

	class Foo extends Panel, Observable {
	  ...
	}

  IMHO, disallowing multiple inheritance of implementation results in much 
design complexity such as you outline below.  

  Note Observable methods such as:  deleteObserver(Observer), deleteObservers(),
countObservers(), etc. should also be exposed in Foo. 

  The evils of multiple inheritance are greatly exaggerated.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 David Geary                                   "I'm a loser baby,
 geary@rmtc.Central.Sun.COM                     So why don't you kill me?"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> I'm running into problems using the Observable class and the Observer interface.
> I have a class (call it Foo) which I would like to be Observable (when a button
> is pressed I need to tell two or more observers about it). I can't make Foo
> a sub-class of Observable because Foo already is a sub-class of Panel. I can't
> have Foo use Obserable (have an Observable instance as a member of Foo) because
> Observable.setChanged() and Observable.clearChanged() are protected functions
> and can only be called by sub-classes of Observable.
> 
> One solution is to make a class like this:
> 
> class MyObservable extends Observable {
> 
>     ...
> 
>     public setChanged() {
> 	super.setChanged();
>     }
> 
>     public clearChanged() {
>         super.clearChanged();
>     }
> }
> 
> And then use it inside my class like this:
> 
> class Foo extends Panel {
>     MyObservable     myObservable;
> 
>     addObserver(Observer o) {
>         myObservable.addObserver(o);
>     }
> 
>     ....
> 
>         /*
>          *  When something changes
>          */
> 
>         myObservable.setChanged();
>         myObservable.notifyObservers("Something Changed");
> 
>     ....
> }
> 
> 
> But, this strikes me as a kludge. Can anyone tell me a better method? Can
> anyone explain why setChanged() and clearChanged() are protected?
> 
> Having fun,
>    Christopher J. Helck

-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post