Metaclass hierarchy - Explanation - Part 2

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Metaclass hierarchy - Explanation - Part 2

Damien Cassou-3
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 ?
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Metaclass hierarchy - Explanation - Part 2

Oscar Nierstrasz

Nice.

Also have a look at:

http://www.iam.unibe.ch/~scg/Teaching/Smalltalk/Slides/07Metaclasses.pdf

I think this is a nice synthesis of several explanations gathered and  
refined over the years.

oscar

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners