Whee!
Stephane Ducasse
ducasse at iam.unibe.ch
Tue May 20 06:10:23 UTC 2003
Hi dominic
I suggest you to have a look at:
http://www.iam.unibe.ch/~ducasse/WebPages/Publications.html
Stéphane Ducasse, Evaluating Message Passing Control Techniques in
Smalltalk, In JOOP (Journal of Object - Oriented Programming), N 6,
jun, Vol 12, SIGS Press, pp. 39-44, 1999. online pdf file
also look at instVarAt: and instVarAt:put:
Stef
On Tuesday, May 20, 2003, at 12:37 AM, Dominic Fox wrote:
> OK, now this is quite fun.
>
> Part of my interest in Smalltalk has to do with a more general
> curiosity about
> what happens when you add things like reflection and metaclasses to an
> object
> oriented system (or don't take them away in the first place). This is
> one of
> the things I find myself missing when I'm coding in VB. I like the
> fact that
> in Python, for instance, it's trivially easy to create an object that
> acts as
> a facade for any other objects you tell it to: you just intercept
> messages
> sent to that object using __setattr__ and __getattr__, and pass them
> on to
> the first of the sub-objects that can receive them (or to all of them,
> one
> after another, possibly sequencing their return values into a list or
> tuple).
> Such an object would act as a kind of dynamic proxy; and of course you
> can
> start intercepting those method calls and hooking all sorts of
> side-effects
> up to them as well, if you want to.
>
> So far, in Smalltalk, I have a class "Interceptor" with a private
> variable
> "log" that's initialized to be a Bag. Interceptor has a method
> "intercept:"
> which looks like this:
>
> intercept: aBlock
> ^ [message: |
> self log add: message.
> aBlock value: message]
>
> You pass in a block (that takes a single parameter) and get a block
> back that
> does the same thing, except that Interceptor logs the parameter that
> was
> passed to it. Now for an object foo with a method bar, we can create a
> block
> that passes a message to foo's bar, and intercept *that*:
>
> interceptedFooBar := myInterceptor intercept: [:message | foo bar:
> message]
>
> and so on ad nauseam.
>
> Is there, in fact, a Smalltalk equivalent to __getattr__/__setattr__?
> If not,
> how do you do dynamic proxies (e.g. proxies that don't know until you
> tell
> them what they're proxies for)?
>
> Dominic
>
>
More information about the Squeak-dev
mailing list
|