[2071] in java-interest

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

Re: Fn ptrs & ... callbacks!?

daemon@ATHENA.MIT.EDU (Sal Cataudella)
Fri Sep 22 17:43:16 1995

Date: Fri, 22 Sep 1995 14:25:42 -0400 (EDT)
From: Sal Cataudella <salc@ovid.com>
To: Philip Brown <phil@bolthole.com>
Cc: java-interest@java.sun.com
In-Reply-To: <199509220855.IAA17734@shellx.best.com>


On Fri, 22 Sep 1995, Philip Brown wrote:

> [ Steve Witham writes ]
> > 
> > >It's also a problem for handling callbacks from GUI controls.
> > 
> > I thought Java got rid of callbacks by having threads...didn't it?
> > Callbacks are just a dumb, inside-out way to implement threads.
> 
> No they are not. Callbacks are a way of implementing Event-driven
> programming.
> This should not be confused with threading. They are completely separate
> issues.


Not only that, but method pointers, when used for callback purposes,
allow you to reuse a class's code without having to subclass.

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.
One of the OO lessons I learned from C++ is that:
	"re-use comes thru instantiation, specialization comes thru
	 subclassing."

Since pointer paranoia abounds in Java (for good reasons),
perhaps one should take a moment and realize that since objects are
really close to C++ reference variables' (except that java's can be
reset anytime ?) anyway, we already have pointers in java!

To implement method pointers, all that is needed 
is a method reference type, which can be made to refer to a specific
method.

eg:
	class Foo extends Object {
	  ...
	  void bar( ....) { ....};
	} ;

	Foo aFoo = new Foo (whatever) ;

	Method mRef = aFoo.bar ;//reference to method 'bar' note lack of param

	aFoo.mRef( blah, blah ) ; // execution of method 'bar' via reference

Note that this would not be implemented as a *hard* code address, 
but could instead be implemented ala Objective C method Id style.

How about it, Arthur?


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

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