[squeak-dev] Re: Traits on Gemstone

Matthew Fulmer tapplek at gmail.com
Mon Nov 3 22:58:35 UTC 2008


On Sun, Nov 02, 2008 at 10:52:15PM -0600, Sophie (itsme213) wrote:
> "Matthew Fulmer" <tapplek at gmail.com> wrote in message
> > On Sun, Nov 02, 2008 at 10:10:49PM -0600, Sophie (itsme213) wrote:
> >> I have tried several combinations of poking around #methodDictionary,
> >> #addSelector, even CompiledMethod>>#getSource fed to Compiler. I only
> >> succeed in messing up things and getting a large red methods-list pane in 
> >> my
> >> browser window :-)
> 
> > Well, the easiest way is to copy-paste.
> 
> Ah, why didn't I think of that :-) I'd much prefer it programmed.
> 
> > What are you trying to do?
> 
> Migrate off traits to ease migration to Gemstone by (a) replacing the trait 
> with a plain class, and (b) programatically pushing methods from that class 
> into other classes.

Traits support flattening, which means that you leave all the
traits methods in the class, but forget that they came from
elsewhere. To remove the traits from a class, but leave the
methods alone, I think you just do this:

aClass purgeLocalSelectors
aClass traitComposition: nil

If you need portability between Squeak and Gemstone, you should
probably just forget about using Traits. Flatten all your
classes using the above two lines, then delete all your traits.


However, if you still want to do your idea, you should be aware
that the protocol for building methods on different Smalltalks
is not standardized. Look inside Behavior, ClassDescription, and
Class inside Gemstone, and see what it does. Maybe you can
abstract it away.


To replace a trait with a plain class:
- make a class that has nothing but that trait
- flatten the class
- delete the trait

Here is the code:

Object subclass: #MyClass
    uses: MyTrait
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'MyStuff'

MyClass purgeLocalSelectors
MyClass traitComposition: nil

MyTrait removeFromSystem

-- 
Matthew Fulmer -- http://mtfulmer.wordpress.com/



More information about the Squeak-dev mailing list