How to implement a Proxy
Paolo Bonzini
bonzini at gnu.org
Fri Sep 28 08:16:52 UTC 2007
Colin Putney wrote:
>
> On Sep 27, 2007, at 9:46 PM, Alejandro Martínez 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)).
>
> There's no need to do this kind of thing. If your ProxyObject class
> doesn't implement #at:put: the VM will create the Message object for you
> and send #doesNotUnderstand: to your proxy. You only need to implement
> the messages you *don't* want forwarded.
I think the problem is exactly that he's not subclassing ProtoObject.
So, #at:put: will go to a primitive instead of being trapped.
Paolo
More information about the Squeak-dev
mailing list
|