[Traits] analogue for #canUnderstand: ?

Adrian Lienhard adi at netstyle.ch
Wed Jul 12 18:53:43 UTC 2006


On Jul 12, 2006, at 11:20 , Klaus D. Witzel wrote:

> I have to reflect on "classic" Behavior and also on traits. For  
> Behavior I can use
>
> 	aTraitOrBehavior canUnderstand: aSelector
>
> and be assured that at another point in time, in the same image  
> instances of aTraitOrBehavior will respond to aSelector.
>
> What query must be used for Trait and TraitComposition, in the same  
> sense, i.e. users of this traits / composition will definitely  
> respond to aSelector.

just like classes, a traits also understand #canUnderstand:

"TPureBehavior canUnderstand: #canUnderstand:" --> true

because "TPureBehavior selectors includes: #canUnderstand:" --> true
and the trait TPureBehavior is used both by the classes Behavior and  
TraitBehavior.


for trait compositions, there is #includesMethod:
e.g., "(TPureBehavior @ {#foo: -> #compile:}) asTraitComposition  
includesMethod: #foo:" --> true

> And what query must be used in analogue to #isBehavior when  
> aTraitOrBehavior is Trait or a TraitComposition. I have to avoid  
> DNU in images without traits.

whether an object is a trait: #isTrait
there's no such test for trait compositions because I never needed  
one -- you would have to add one yourself. Also, of course, #isTrait  
will not work in older images unless you add this method as an  
extension to Object.

HTH,
Adrian

>
> I can find out many details by myself but would like to check  
> against an expert opinion. Thank you in advance.
>
> /Klaus
>
>




More information about the Squeak-dev mailing list