Help needed for a spying object
Mark van Gulik
ghoul6 at home.com
Thu Oct 4 09:37:58 UTC 2001
On Thursday, October 4, 2001, at 03:58 am, ducasse stephane wrote:
> I'm trying to finish to write a column on using reflection in Squeak.
> I wanted to show a little spy that puts on the transcript all the
> sent to the spied object.
> ProtoObject subclass: #Spy
> instanceVariableNames: 'spyedObject '
> classVariableNames: ''
> poolDictionaries: ''
> category: 'Scaffolding'
> Spy>> doesNotUnderstand: aMessage
> Transcript nextPutAll: '*' ; flush.
> ^ spyedObject perform: aMessage selector withArguments: aMessage
> Then when I open an inspector on t and send messages there are not
> captured. I don't understand why. I alreadyplayed a lot with
> become: and
> nasty stuff in VW but here I'm stuck.
I'm rusty on Squeak, but the code that opens the inspector might be
#yourself or some such message. Consider what happens when you send
#yourself to a Spy. It redirects the message to the spied object, which
then returns the spied object. Spy then returns that very same spied
breaking the encapsulation you intended. A quick 99% fix is to check if
the message returns the spied object, and if so return the Spy instead.
The second problem (Morphs) might be related to the first, or it might be
completely different. You might want to see if my suggestion fixes the
second problem too.
More information about the Squeak-dev