[2106] in java-interest
Re: Fn ptrs & ... callbacks!?
daemon@ATHENA.MIT.EDU (Sal Cataudella)
Mon Sep 25 15:08:10 1995
Date: Mon, 25 Sep 1995 11:45:03 -0400 (EDT)
From: Sal Cataudella <salc@ovid.com>
To: Gary Aitken <garya@village.org>
Cc: Andrew Wason <aw@bae.bellcore.com>, java-interest@java.sun.com
In-Reply-To: <9509240623.AA21886@.montana.com>
On Sat, 23 Sep 1995, Gary Aitken wrote:
> >> Let's say you need to create 2 sliders, and have each one of them invoke
> >> a different method. With the method ptr callback technique, you can create
> >> 2 instances of sliders and simply register the method and object pointers
> >> you wish to have invoked. Thus , you are reusing code (the slider's)
> >> by instantion, not by subclassing. Without the method callback technique,
> >> you are *forced* to subclass *twice*, in order to reuse code.
> >
> >You could define a new interface, Callbackable that defines a
> >callback method. Then create a single slider subclass that
> >manages a Vector of Callbackable instances. In the sliders
> >callback method, call the callbackable method of each
> >Callbackable in the Vector.
> >
> >So now you can give every slider one or more different
> >Callbackable objects that implement your callback functionality.
> >Your callback functionality is independent of your slider class.
> >
> >If you change all your UI components that use callbacks (Button
> >etc.) to manage a Callbackable Vector, then you can even share
> >Callbackable instances among different UI instances (e.g. I write
> >a Callbackable that pops up some dialog, I can stick that in a
> >menu item and a button - when either one is clicked it will
> >execute the same shared code and pop up a dialog).
> >
> >I don't see how this is worse than function pointer callbacks, I
> >prefer it. In C you typically need to register some void* pointer
> >along with your function pointer to give your function some
> >context. With Callbackable, you're encapsulating that data in
> >the Callbackable object in a typesafe way.
>
>This is all true. However, it would be far better if the callblackable vector
>were part of the base classes. If you think of code reuse and general systems
>which want to be able to deal with arbitrary objects, the last thing you want
>to have to do is derive a new class for every darn class someone writes.
Actually, with the Callbackable vector scheme you will be subclassing
for *every* method which you want to have called back, not just every
new class which you want called back.
Again, polluting of the class name space would be avoided with a builtin
method reference type.
> Gary Aitken garya@village.org
> -
> Note to Sun employees: this is an EXTERNAL mailing list!
> Info: send 'help' to java-interest-request@java.sun.com
>
Sal Cataudella email: salc@ovid.com
Ovid Technologies (formerly CD Plus) phone: 212-563-3006 ext. 406
333 Seventh Ave., 4th Floor fax: 212-563-3784
New York, NY 10001
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com