Friday, November 5, 2010

MetaClass

I ran across this from an old email.  One of my favorite little snippets.

6.3.3  The Class Metaclass

As objects, metaclasses are also instances of a class, and that class is
also a metaclass since the metaclasses are class objects.  However,
unlike classes, all metaclasses share the same protocol, namely the
message that creates their single instance.  Therefore, the metaclass
objects are all instances of the same class, namely the system class
Metaclass. For any class C, the expression C class class returns
Metaclass. Metaclass defines a single instance variable, thisClass,
which refers to the metaclass's instance.

Now consider Metaclass class, which is the metaclass of Metaclass. Every
metaclass is an instance of Metaclass, so Metaclass class is an instance
as well.  Because Metaclass is the instance of Metaclass class, this is
the point of circularity in the system with respect to class (i.e.,
"instance of") references. The class/instance relationships among
objects, classes, metaclasses, Metaclass and Metaclass class, are
illustrated in Figure 6.6

If you can make sense of that on a first read, you get a gold star.

No comments:

Post a Comment