[Q] mixin pattern - how to use an alternate Behavior for Class

Rob Withers rwithers12 at mediaone.net
Tue Jan 29 13:02:06 UTC 2002


At 02:12 AM 1/29/2002, you wrote:
> > you said:
> > > In case (1a) you break this parallel inheritance hierarchy because
> > > 'MixinClass' is a subclass of
> > > 'ClassDescription' but 'MixinClass class' is no subclass of
> > > 'ClassDescription class' (in fact,
> >
> > this is not true, 'MixinClass class' is a subclass of 'ClassDescription
> > class'.
> >
> > > 'MixinClass class' == 'MixinClass'). In your concerte
> > > example, this means
> > > that 'MixinClass' inherits
> > > from:
> > >
> > > ClassDescription
> > > Behavior
> > > Object
> > > ProtoObject
> > >
> > > but 'MixinClass class' (== 'MixinClass') does not inherit from
> > > 'ClassDescription class', 'Behavior
> > > class', etc.
> >
> > again this is not true.
> >
> > Here is my option (1b)
> > > > 1a) meta _ Metaclass new.
> > > > meta
> > > > superclass: MixinClass
> > > > methodDictionary: MethodDictionary new
> > > > format: MixinClass format.
> > > > newClass _ meta new.
>
> > > > 2) newClass
> > > > superclass: newSuper
> > > > methodDictionary: MethodDictionary new
> > > > format: newFormat;
> > > > contextClass: aContextClass;
> > > > setInstVarNames: instVars;
> > > > organization: nil.
> > > > ^newClass
>
>Rob,
>
>Yes, you are right! I didn't read the example right! You define here a new
>class (not MixinClass) which has MixinClass as the superclass of the
>metaclass. Therefore, the parallel inheritance chains break for this new
>class and not for MixinClass.

Hi Nathanael,

We are on the same page now, I believe, you with my problem and me with a 
clearer understanding of the way this is structured.  Superb!  The reason 
my original attempt of:

1b)     meta _ Metaclass new.
         meta
                 superclass: newSuper class
                 methodDictionary: MethodDictionary new
                 format: MixinClass format.
         newClass _ meta new.

doesn't work is not due to the shape of the instance.  It really is shaped 
to be a MixinClass, due to the format of the metaclass.  The problem is 
that the metaclass inheritance doesn't include MixinClass, so none of the 
protocol is understood.  The only way I was able to make this work is to 
break the inheritance of the metaclasses.  Wow!  Unless we break the 
multiple inheritance rule, there doesn't seem to be a way to maintain the 
inheritance structure, at the metaclass level, and have my new class 
(MyProxyMixin) understand MixinClass protocol.  Would you agree?

you also wrote:
>Yes, that's right, there are no -direct- instances of Class.
>All the ST-80 "classes" (Object, Integer, etc.) are instances of their
>metaclasses (Object class, Integer class, etc.) and these are again
>instances of Metaclass.
>However, since Object class, Integer class etc. are subclasses of Class (try
>'Object class superclass superclass'), the ST-80 "classes" Object, Integer,
>etc. are subinstances of Class. (Try 'Class allSubInstances').
>
>Summary:
>1) The ST-80 "metaclasses" Object class, Integer class, etc. are subclasses
>of Class and instances of Metaclass
>2) The ST-80 "classes" Object, Integer, etc. are -instances- of subclasses
>of Class (namely, of the metaclasses mentioned in 1).

You know, I have probably read something that said that very thing and just 
didn't read or think carefully enough about it's implications.  Now that I 
am on this side of the fence, I see the structure clearly.   All of the 
metaclasses must inherit from Class, or none of it works.  The only way to 
change the Behavior representing a class is to root a new hierarchy with 
the new Behavior as the superclass of the first metaclass.  This may not be 
a bad idea, since I don't plan on having instances of the resulting class.

Like this:

class inheritence
  nil (an UndefinedObject)
    -> MixinProtoObject (shape of MixinClass)
      -> MixinObject (shape of MixinClass)
        -> MyMixin  (shape of MixinClass)

metaclass inheritence
  MixinClass (Class)
    -> MixinProtoObject class (a Metaclass)
      -> MixinObject class (a Metaclass)
        -> MyMixin class (a Metaclass)

Cheers,
Rob




More information about the Squeak-dev mailing list