How to implement a Proxy

Colin Putney cputney at wiresong.ca
Fri Sep 28 06:31:58 UTC 2007


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.

Colin




More information about the Squeak-dev mailing list