#perform:#orSendTo: question

Stephan Rudlof sr at evolgo.de
Mon Sep 20 16:29:53 UTC 2004


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 ]
> 
> 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).


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



More information about the Squeak-dev mailing list