#perform:#orSendTo: question

Stephan Rudlof sr at evolgo.de
Tue Sep 21 15:22:15 UTC 2004


Alexandre and Sam,

Alexandre Bergel wrote:
> Stephan,
> 
> I do not understand. If you have B subclass of A. and B>>foo exists.
> 
> 'B new perform: #foo orSendTo: whatever' will perform 'whatever foo'.
>  I agree with Sam.

You are right!
My thinking (see below) has been wrong here.


> I will do a fix for that. But I remember that there was a long
> discussion about this point a while ago...
> 
> Alexandre
> 
> 
> On Mon, Sep 20, 2004 at 06:29:53PM +0200, Stephan Rudlof wrote:
> 
>> Samuel,
>> 
>> Samuel Tardieu wrote:
>> 
>>> I wonder why the implementation of Object>>#perform:#orSendTo:
>>> looks counterintuitive to me:
>>> 
>>> perform: selector orSendTo: otherTarget "If I wish to intercept
>>> and handle selector myself, do it; else send it to otherTarget" ^
>>> otherTarget perform: selector
>>> 

>>> I would have naively thought that a correct implementation was:
>>> 
>>> (self respondsTo: selector) ifTrue: [ ^self perform: selector ] 
>>> ifFalse: [ ^otherTarget perform: selector ]

And this indeed seems to be the right fix.

BTW: There are other possible delegation mechanisms of course.

>>> 
>>> Can I find somewhere an explanation of how this selector is
>>> supposed to be used?
>> 
>> If there is an implementation of selector, it resides in a
>> *sub*class of Object and will be performed automatically, since the
>> corresponding message will be send to the subclass corresponding to
>> the receiver object first. On the other hand, if there is no
>> *sub*class of Object implementing selector, the method in Object
>> comes into play (method lookup goes from the subclass corresponding
>> to the receiver up to Object).

The idea here could be rescued by changing #doesNotUnderstand: into
something looking for a somewhat registered delegation object, or to
handle the MessageNotUnderstood exception raised there, but I stop
thinking here.


Greetings
Stephan


>> 
>> 
>> Greetings Stephan
>> 
>> 
>>> Sam
>> 
>> -- Stephan Rudlof (sr at evolgo.de) "Genius doesn't work on an
>> assembly line basis. You can't simply say, 'Today I will be
>> brilliant.'" -- Kirk, "The Ultimate Computer", stardate 4731.3
> 
> 

-- 
Stephan Rudlof (sr at evolgo.de)
   "Genius doesn't work on an assembly line basis.
    You can't simply say, 'Today I will be brilliant.'"
    -- Kirk, "The Ultimate Computer", stardate 4731.3



More information about the Squeak-dev mailing list