Hello, everyone.
This is the fifth sequence on inheritance and lookup.
We'll be covering messaging
and lookup algorithms for metaclasses.
In Pharo,
everything is an object,
and objects can receive messages.
So classes are objects, too.
And since objects can receive messages,
classes can receive messages.
The messaging mechanism is exactly the same,
whether the receiver is a class or other object.
There is only one way to look up a method.
This is the lookup algorithm we've seen several times
in earlier sessions.
Now let's look at the example
of messaging a class.
Understand the basic principle:
Since classes are objects,
and each object is linked to a class,
that is, an instance of a class,
aNode is an instance of Node class.
Since Node class is an object,
Node class is an instance of another class.
It is called Node class.
So, aNode is an instance of Node class,
and Node class is an object that is an instance of Node class class.
If that's the way it is, you may wonder
Node class is a class; a class is an object, an instance of a class.
which class Node class is an instance of.
You will see that in the next sequence, on metaclasses.
Here are a few examples.
Here, the object, aWorkstation, is an instance of Workstation class.
Workstation is a subclass of Node, a subclass of Object.
Here, you must pay attention to the arrows.
The arrow with a blank tip
indicates a subclass relationship.
Node is a subclass of Object.
Workstation is a subclass of Node.
The arrow with a black point,
is sometimes represented as a simple two-line arrow, too.
It indicates instanciation.
aWorkstation is an instance of Workstation.
Workstation is an instance of Workstation class.
Likewise, Object is an instance of Object class.
If I message
the object aWorkstation,
the lookup algorithm searches the aWorkstation class.
Then it goes up through superclasses
until it finds a matching method.
The mechanism is exactly the same
when I message the Workstation class.
For example, if I send the message "new"
to Workstation, the lookup algorithm
searches Workstation class for a method called "new."
If it finds it here, it executes it.
If it does not find a match, it moves up to the superclass,
and then up to the next superclass.
And so on. This hierarchy continues.
I'll leave you with this slide summing up messaging
to standard objects and classes as standard objects.
Here's what to remember:
A class is an object like any other.
Messages can be sent to objects, and therefore to classes.
The lookup mechanism is exactly the same in both cases.
It starts searching in the class of the receiver,
and then searches each superclass in the inheritance chain
until it finds a matching method.
You'll learn more about metaclasses in "Understanding Metaclasses."