How to implement a Proxy

Michael van der Gulik mikevdg at gmail.com
Sat Sep 29 06:28:07 UTC 2007


On 9/28/07, Alejandro Martínez <alemartinez2112 at gmail.com> wrote:
>
> I was thinking about implementing a Proxy but instead the usual way which
> I believe is subclassing from ProtoObject, I subclassed from Object a
> ProxyObject with an iVar called encapsulatedObject, and then write
>
> ProxyObject >>doesNotUnderstand: aMessage
>     ^aMessage sendTo: self encapsulatedObject
>
> Then for every message I need to intercept, I write:
>
> ProxyObject >>at: index put: value
>     ^self doesNotUnderstand: (Message selector: #at:put:
>                                                          arguments: (Array
> with: index with: value)).
>
> ProxyObject>>asString
>     ^self doesNotUnderstand: (Message selector: #asString).
>
> ProxyObject>>name
>     ^self doesNotUnderstand: (Message selector: #name).
>
> ....
>
> ok... you get the idea.
> But I was reading a paper called "Evaluating Message Passing Control
> Techniques in Smalltalk" from Stéphane Ducasse, and supposed my idea
> qualified as "minimal object". He wrote:
>
> "The right technique to create a minimal object is the following:
> (1) creation of a subclass of Object,
> (2) assignment of the superclass link to nil and
> (3) definition of the minimal behavior by copying the needed methods from
> Object"
>
> But I've implemented it without (2) and doing some message replication
> mentioned above (currently I have no more than 15 of those kind of messages)
> it would, at first, bypass the problem described in the "Problems" section:
>
> "This leads to the problem of the interpretation by the minimal object of
> messages that were initially destined for the controlled object"
>
> Hope I've understood the right way. However, something still smells bad to
> me... and that's why I'm writing to the list for some advice or suggestion.
> The only real problem I've experimented is when the replication of #ifNil:
> nilBlock takes place, this doesn't seem to work:
>
> ProxyObject>>ifNil: nilBlock
>     ^self doesNotUnderstand: (Message selector: #ifNil: argument:
> nilBlock).
>
> (my guess here is there's some optimization thing walking around)
>
> So, for those cool guys here, can you tell me if there is a possible
> drawback or unwanted behavior I'm not seeing? If true in which case would
> happen? Is this a valid way of implementing a Proxy or there's something
> I've missing? (I suspect a performance penalty, but I'm not sure about this)
>


Hi Alejandro

I've got a pre-packaged, working version of a proxy. I've spent a long time
trying to get it to work without crashing inspectors and debuggers, and it's
still not perfect. Give it a try if you want:

http://www.squeaksource.com/DPON/MessageCapture-mvdg.9.mcz

Gulik.

-- 
http://people.squeakfoundation.org/person/mikevdg
http://gulik.pbwiki.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20070929/06e1ea2b/attachment.htm


More information about the Squeak-dev mailing list