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

Casimiro de Almeida Barreto casimiro.barreto at gmail.com
Mon Oct 22 14:35:40 UTC 2012


On 21-10-2012 22:49, Levente Uzonyi wrote:
> On Sun, 21 Oct 2012, Casimiro de Almeida Barreto wrote:
>
>> It is also interesting that when you modify a Trait message inside a
>> class (either directly in the browser or else during debbuging),
>> there'll be a new message, particular to that class that diverges from
>> the message in Traits, causing a kind of "overload" (two messages of the
>> same name, one in the Traits definition other in the class definition).
>> If developer doesn't get it ASAP, it can be source of huge trouble.
>
> I guess that's how Traits should work.
So so...

Because sometimes developer is tempted to correct things from/inside
debugger. Then he'll have two versions of the method: a corrected
version for the class in question and a wrong version elsewhere.

CdAB
>
>
> Levente
>
>>
>> CdAB
>>
>> On 21-10-2012 02:47, 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
>>>
>>>
>>
>>
>>
>
>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 259 bytes
Desc: OpenPGP digital signature
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20121022/a9dc70ba/signature.pgp


More information about the Squeak-dev mailing list