Foundation question

Ned Konz ned at bike-nomad.com
Tue Jul 11 23:22:32 UTC 2000


Michael Bauers wrote:
> 
> I am been attempting to understand the class creation mechanism.
> 
> I am getting confused betweebn the class 'Class' and the class 'Metaclass'.
> 
> I looked at the class 'ClassBuilder' and it appeared to create classes as
> instances of 'Metaclass'.
> 
> If that is the case, what is the class 'Class' used for?  Is anything
> actually an instance of 'Class' ?

When you define a class, you're actually adding two objects to the
system:
the class (which is an instance of Class), and the metaclass (which is
an instance
of Metaclass). So,

Dictionary isKindOf: Class              true
Dictionary class isKindOf: Metaclass	true

They point to each other; Metaclass>>theNonMetaClass and Object>>class
respectively
return those object references.

Their behavior is different but they share class variables. The Class is
responsible
for instantiating objects of the class.

>From the class comment in Metaclass:

My instances add instance-specific behavior to various class-describing
objects
in the system. This typically includes messages for initializing class
variables and instance creation messages particular to a class. There is
only
one instance of a particular Metaclass, namely the class which is being
described. A Metaclass shares the class variables of its instance.

[Subtle] In
general, the superclass hierarchy for metaclasses parallels that for
classes.

Thus,

	Integer superclass == Number, and

	Integer class superclass == Number class.

However there is a singularity at Object. Here the class hierarchy
terminates,
but the metaclass hierarchy must wrap around to Class, since ALL
metaclasses
are subclasses of Class. Thus,

	Object superclass == nil, and

	Object class superclass == Class.

-- 
Ned Konz
currently: Stanwood, WA
email:     ned at bike-nomad.com
homepage:  http://bike-nomad.com





More information about the Squeak-dev mailing list