[Newbies] Traits

Bert Freudenberg bert at freudenbergs.de
Tue Sep 25 08:04:18 UTC 2007

On Sep 25, 2007, at 2:00 , Nick Ager wrote:

> Armed with new knowledge of Traits gained from the excellent  
> "Squeak By
> Example" I tried:
>     Smalltalk allClasses select: [:each | each hasTraitComposition]
> which gave:
> an OrderedCollection(ActionSequence BalloonBezierSimulation  
> BalloonEngine
> BalloonEngineConstants BasicRequestor Behavior BrowserProvider
> ....WorldMenuProvider XMLTokenizer ZipConstants ZipFileConstants)
> However browsing to a random class say "ActionSquence", doesn't  
> show any
> evidence of Trait composition. Is this a problem with the current  
> browser?

No. #hasTraitComposition only checks if the traitCompositions  
variable is not nil - the composition may still be empty. Which can  
happen quite easily since that variable is lazily initialized by  
sending #traitCompositions.

This appears to be by design, the codebase is scattered with  
#hasTraitComposition checks. But missing only one occurrence where  
#traitCompositions is sent unguarded by #hasTraitComposition will get  
the variable populated. And it will never get reset to nil as far as  
I can tell.

- Bert -

More information about the Beginners mailing list