Instance-specific behavior question (like Ruby?)

Ben Schroeder bschroeder at procro.com
Tue Mar 23 14:38:02 UTC 2004


> I am somewhat familiar with the idiom of doing instance 
> specialization by
> overriding "doesNotUnderstand".
> 
> Ruby provides a different and more direct way of doing such 
> prototype based
> programming: it simply makes the instance belong to a new 
> (anonymous) class,
> and puts any instance-specific behavior on that class. It 
> provides a syntax
> to define that behavior (since the class is anonymous).
> 
> Is there a way to do this in Squeak? I'm a relative Squeak newbie ...
> 
> [Email copy of reply greatly appreciated]

In addition to the things mentioned in Avi's and Bert's replies, there's a Squeak Prototypes package on SqueakMap.  It lets you make "prototype objects" whose inspectors can add instance-specific variables and methods, as well as delegate behavior to other prototype objects.  Its view of prototypes is similar to that of the Self language, if you're familiar with that.

Unfortunately (unlike the Singletons package, from my understanding) you have to start with a PrototypeObject in the first place.  I've been kicking around some changes to that package (I'm not one of the original authors; just messing around with it), and one of the things we've thought about here is like that: that whenever you started saying prototype-like things to an object, it would add all the instance-specific machinery behind the scenes.

If you (or anyone) is interested in the changes we've made, please write me off-list.  I will post them to SqueakMap, maybe under some other name so as not to step on the original package, at some point.  There's not much there yet - other than what's already on SqueakMap, the biggest two things are saving the source code of prototype methods and being able to write PrototypeObjects to a ReferenceStream (handy for shuttling them around a network).

Regards,
Ben Schroeder



More information about the Squeak-dev mailing list