Inheritance and Lookup
5: Lookup in metaclasses
Damien Cassou, Stéphane Ducasse and Luc Fabresse
http://stephane.ducasse.free.fr
Goal
- in Pharo, everything is an object
- objects can receive messages
- classes are objects too
Classes can receive messages. The mechanism is exactly the same
Only One Lookup Rule
The lookup starts in the class of the receiver then:
- if the method is defined in the class, it is returned
- otherwise the search continues in the superclass
A Class is an Instance of Another Class
Class X
is always the unique instance of the class X class
:
Node
is a class and an object
- each object is an instance of a class
- the class of
Node
is Node class
- the class
Node class
is automatically created
Superclass Chain
Lookup of Class Methods is No Different
What You Should Know
- A class is an object
- A class can receive messages
- Method lookup is exactly the same as for all objects:
- go to the class of the receiver
- follow inheritance chain
- More during the lecture Understanding Metaclasses
/