[Aaaahhhhhh - lightning strikes] RE: [Q] mixin pattern - how to use an alternate Behavior for Class

Withers, Robert rwithers at quallaby.com
Mon Jan 28 20:34:43 UTC 2002


Nathanael et al,

I have just realized something.  It's a classic 'aahhhh' situation with the
meta-level of Smalltalk (this is true in VW as well).   Do you realize that
there are no instances of Class anywhere in the system.  None, nada, zero,
zip!  Try doing 'Class allInstances' to prove it!  What is true is that
whatever the objects are, that represent classes, they are _subclasses_ of
Class.  Unbelievable!

I wrote:

> we can verify that these definition objects are instances of 
> the correct
> class with:
>   Morph class isKindOf: Metaclass
>   Morph isKindOf: Class
>   Object class isKindOf: Metaclass
>   Object isKindOf: Class
> and even:
>   ProtoObject class isKindOf: Metaclass
>   ProtoObject isKindOf: Class


But the calls to <Class> isKindOf: Class is not doing what we think it is.
It isn't checking the extend class hierarchy, but rather the implicit
hierarchy of metaclass superclasses (the Classes themselves).   As it turns,
this is rooted at the class Class, so it responds true, but the intervening
classes are _not_ instances of class.  They just happen to have the same
format and shape that an instance of Class would have and it inherits all of
the behavior of Class, since its class hierarchy is rooted at Class.

So let me correct my description of the parallel hierarchies:

metaclass inheritance (with what it is)
 Class (class Class) 
   -> ProtoObject class (a Metaclass) 
     -> Object class (a Metaclass) 
       -> Morph class (a Metaclass) 


class inheritance (with what it is)
Except for nil, this is an object that is shaped like a Class, but isn't.
It acts like a Class because behavior is inherited from the metaclass
inheritance, rooted at class Class.

 nil (UndefinedObject)
   -> ProtoObject (an object that is shaped like a Class)
     -> Object (an object that is shaped like a Class)
       -> Morph (an object that is shaped like a Class)

Cheers!
Rob



More information about the Squeak-dev mailing list