[Traits] analogue for #canUnderstand: ?

Klaus D. Witzel klaus.witzel at cobss.com
Thu Jul 13 04:58:51 UTC 2006


Hi Adrian,

on Wed, 12 Jul 2006 20:53:43 +0200, you wrote:
> 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.

Yes, I've seen that but wasn't sure this coveres all cases.

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

Then, together with the above, the following must hold for each and every  
nut and bolt:

  ((something respondsTo: #canUnderstand:) and: [something canUnderstand:  
aSelector])
or:
  ((something respondsTo: #includesMethod:) and: [something includesMethod:  
aSelector])


>> 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

... a situation which I often value as good design :)

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

Right. For the moment I'll let #respondsTo: do the work, until performance  
demands something else.

> HTH,

Yes. I got one bit more than I hoped for, a simple expression governed by  
a single quantifier.

Thank you Adrian.

/Klaus

> 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