[squeak-dev] Re: Traits in Trunk - how to remove a trait from a class?

Levente Uzonyi leves at elte.hu
Sun Oct 21 14:33:04 UTC 2012

So the problem is that simply removing the line

 	uses: ATraitCompostition

from the class definition doesn't change the class. It is because

Class >> #subclass:instanceVariableNames:classVariableNames:poolDictionaries:category:

works differently than

Class >> #subclass:uses:instanceVariableNames:classVariableNames:poolDictionaries:category:

The former should also sets the TraitComposition of the new class (to an 
empty one). I think that notifying a class change in the latter is not 
right, because it might be a class creation too. Also, shouldn't the value 
of oldClass be the class itself if it exists instead of a copy of the 

The same is also true for the other class defition methods (variable*, 


On Sat, 20 Oct 2012, Chris Cunningham wrote:

> On Fri, Oct 19, 2012 at 1:39 AM, Andreas.Raab <andreas.raab at gmx.de> wrote:
>> Chris Cunningham wrote
>>> Is there a way (UI, code) to make a class NOT use any traits after a
>>> class has a Trait assigned to it?
>> Try this:
>>   Trait flattenTraitMethodsInClass: MyClass.
> That would probably work well, but I wanted to remove the Trait and
> all of the behavior related to the Trait from the class.  I could do
> this and then delete the methods, but that isn't really efficient.
> I did find the 'right' way to do this.  To add a trait to a class, you
> change the definition of the class in the browser to look like:
> Object subclass: #AClass
> 	uses: ATraitComposition
> 	instanceVariableNames: ...
> To remove that trait (and any others), change the definition to be:
> Object subclass: #AClass
> 	uses: Array new
> 	instanceVariableNames: ...
> This will remove the Trait and the behavior from the class (and, for
> that matter, change the class definition code snippit).  Odd, but it
> works.
> In my case, the goal was a temporary trait usage while building the
> parser, with the intention of removing the behavior from all of the
> classes later.  Or, of course, removing it from other classes that I
> accidentally added the trait to.
> -Chris

More information about the Squeak-dev mailing list