[Newbies] Metaclass hierarchy - Explanation - Part 1

Damien Cassou damien.cassou at laposte.net
Wed Aug 30 14:58:54 UTC 2006


Hi,

I would like to try explaining what is the metaclass hierarchy of
Smalltalk. This is always something new smalltalkers have problem with.
It would be interesting if an experienced smalltalker read this mail and
correct it when I'm wrong.


To understand this, you have to know the following three rules by heart:

1) In Smalltalk, everything is an object
2) In Smalltalk, each object is an instance of a class
3) In Smalltalk, each class has a superclass but one called Object


(in squeak, Object has a superclass called ProtoObject and this class
has no superclass).


Lets start with the string:


'my string'


rule 1) tells us that this is an object.
rule 2) tells us that this is an instance of a class. Here the class is:


String


rule 1) tells us that String is an object.
rule 2) tells us that String is an instance of a class. The class is:


String class


rule 1) tells us that 'String class' is an object.
rule 2) tells us that 'String class' is an instance of a class. The
class is:


Metaclass


rule 1) tells us that Metaclass is an object.
rule 2) tells us that Metaclass is an instance of a class. The class is:


Metaclass class


rule 1) tells us that 'Metaclass class' is an object.
rule 2) tells us that 'Metaclass class' is an instance of a class. The
class is:


Metaclass


Ok, we have a loop here so the rules are always verified. Cool !
Explanation:


- An object is an instance of a class
- A class is the only instance of its metaclass: String is the only
instance of the metaclass 'String class'.
- Each metaclass is an instance of the class Metaclass.


Hope this is clear. If not, please ask.


More information about the Beginners mailing list