logo       

Metaclass hierarchy - Explanation - Part 2: msg#00249

lang.smalltalk.squeak.beginners

Subject: Metaclass hierarchy - Explanation - Part 2

In Smalltalk,

1) Everything is an object
2) Each object is an instance of a class
3) Each class has a superclass but one called ProtoObject (in squeak)
4) A class is the only instance of its metaclass
5) Each metaclass is an instance of the class Metaclass


The browser can inform you what are the super classes of a given class.


The super class of

Collection


is Object. The super class of Object is


ProtoObject


ProtoObject has no superclass.


What are the super classes of metaclasses ? The super class of 'Collection class' is 'Object class, which super class is 'ProtoObject class'. We can see that classes hierarchies and their metaclasses hierarchies are parallel.

But metaclasses goes further because 'ProtoObject class' is not 'ProtoObject' and we said that only ProtoObject has no superclass. What is the superclass of 'ProtoObject class' ? This is

Class


And this is perfectly normal: when you say 'Collection is a class', this is true. It means, that Collection is an instance of Class or one of its subclasses. Same thing when you say 'This blue car in my street is a vehicule'. The blue car could be an instance of the class Car which could be a subclass of Vehicule.


Imagine you want to add an instance variable to the class Collection. You will use something like:

Collection addInstVar: 'newVar'.


You send the message #addInstVar: to Collection. Messages are sent to objects and should be implemented in the class of this objects. So, #addInstVar: should be implemented in 'Collection class' or one of its super classes. This messages is looked up in the hierarchy of 'Collection class' and an implementation if found in the class Class.


Is this still ok ?


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise