[Newbies] "Callback" design pattern

Matthew Fulmer tapplek at gmail.com
Sat Jun 2 17:51:53 UTC 2007

On Sat, Jun 02, 2007 at 05:59:02PM +0200, Stephen Davies wrote:
> Hi,
> I've been busy with hooking Squeak to Asterisk via the Asterisk
> FastAGI protocol.
> I also want to write code to talk to the Asterisk Manager Interface.
> In both cases I need to write an interface to allow others to
> "register" to hande particular AGI call, or to "register" to hear
> about particular AMI events.
> I suppose the method of callback will boil down to "call method
> #whatever on object anObject", or maybe you could register a block to
> be evaluated.
> Now I'm sure there must be an established way to do this in Squeak and
> I'd like to use it.  Or at least code mine in the "usual style".

There are several semi-standard ways to do this in Squeak. The
simplest is the changed-update protocol, defined in Object. The relevant
method categories are "updating" and "dependents access". To use
it, one registers to recieve changes by calling 

anObject addDependent: interestedParty.

Then interestedParty>>update: anObject will be called whenever
anObject>>changed is called. There is also a changed: message if
you need more fine-grained events. It is usually used with
Symbols. All of the PluggableMorphs and PluggableViews use this

A newer method is the Announcements framework, used by
OmniBrowser. See http://wiki.squeak.org/squeak/5734

I am sure there are more. Object has a few method categories
with events in their names, none of which I recognize. There is
also the class category SystemChangeNotification; this is only
used by the compiler and friends to make sure Browsers are kept
up to date as methods and classes change. Tweak and Croquet also
have their own frameworks I believe, based on asynchronous
message sends.

> So could someone point me at some classes in the system that I should look 
> at?
> Thanks,
> Steve
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

Matthew Fulmer -- http://mtfulmer.wordpress.com/
Help improve Squeak Documentation: http://wiki.squeak.org/squeak/808

More information about the Beginners mailing list