WEBVTT

00:00:00.400 --> 00:00:01.400 align:middle
Hello, everyone.

00:00:01.640 --> 00:00:06.720 align:middle
This is the fifth sequence
on inheritance and lookup.

00:00:07.320 --> 00:00:10.320 align:middle
We'll be covering
messaging

00:00:10.600 --> 00:00:13.120 align:middle
and lookup algorithms
for metaclasses.

00:00:13.440 --> 00:00:14.560 align:middle
In Pharo,

00:00:14.880 --> 00:00:16.400 align:middle
everything is an object,

00:00:16.520 --> 00:00:19.400 align:middle
and objects
can receive messages.

00:00:19.800 --> 00:00:23.200 align:middle
So classes are objects, too.

00:00:23.760 --> 00:00:26.120 align:middle
And since objects
can receive messages,

00:00:26.320 --> 00:00:28.040 align:middle
classes can receive messages.

00:00:28.480 --> 00:00:33.480 align:middle
The messaging mechanism
is exactly the same,

00:00:33.800 --> 00:00:37.040 align:middle
whether the receiver is a class
or other object.

00:00:38.840 --> 00:00:42.360 align:middle
There is only one way
to look up a method.

00:00:42.720 --> 00:00:46.280 align:middle
This is the lookup algorithm
we've seen several times

00:00:46.440 --> 00:00:48.320 align:middle
in earlier sessions.

00:00:49.200 --> 00:00:51.560 align:middle
Now let's look at the example

00:00:51.760 --> 00:00:54.200 align:middle
of messaging a class.

00:00:56.240 --> 00:00:58.160 align:middle
Understand
the basic principle:

00:00:58.640 --> 00:01:00.880 align:middle
Since classes are objects,

00:01:02.040 --> 00:01:04.400 align:middle
and each object
is linked to a class,

00:01:04.560 --> 00:01:07.000 align:middle
that is,
an instance of a class,

00:01:07.240 --> 00:01:10.520 align:middle
aNode is an instance
of Node class.

00:01:10.920 --> 00:01:15.040 align:middle
Since Node class
is an object,

00:01:16.160 --> 00:01:19.120 align:middle
Node class is an instance
of another class.

00:01:19.680 --> 00:01:22.560 align:middle
It is called Node class.

00:01:22.880 --> 00:01:25.200 align:middle
So, aNode is an instance
of Node class,

00:01:25.760 --> 00:01:30.120 align:middle
and Node class is an object
that is an instance of Node class class.

00:01:30.840 --> 00:01:33.280 align:middle
If that's the way it is,
you may wonder

00:01:34.120 --> 00:01:39.280 align:middle
Node class is a class; a class
is an object, an instance of a class.

00:01:39.600 --> 00:01:43.400 align:middle
which class Node class
is an instance of.

00:01:43.840 --> 00:01:47.800 align:middle
You will see that in the next sequence,
on metaclasses.

00:01:48.240 --> 00:01:50.560 align:middle
Here are a few examples.

00:01:50.960 --> 00:01:56.880 align:middle
Here, the object, aWorkstation,
is an instance of Workstation class.

00:01:57.040 --> 00:02:00.480 align:middle
Workstation is a subclass of Node,
a subclass of Object.

00:02:00.640 --> 00:02:03.320 align:middle
Here, you must
pay attention to the arrows.

00:02:04.200 --> 00:02:06.360 align:middle
The arrow with a blank tip

00:02:07.000 --> 00:02:09.160 align:middle
indicates a subclass relationship.

00:02:09.400 --> 00:02:12.280 align:middle
Node is a subclass of Object.

00:02:12.640 --> 00:02:14.760 align:middle
Workstation
is a subclass of Node.

00:02:15.040 --> 00:02:17.600 align:middle
The arrow with a black point,

00:02:17.920 --> 00:02:21.800 align:middle
is sometimes represented
as a simple two-line arrow, too.

00:02:22.160 --> 00:02:23.960 align:middle
It indicates instanciation.

00:02:25.320 --> 00:02:27.880 align:middle
aWorkstation is an instance
of Workstation.

00:02:28.160 --> 00:02:30.600 align:middle
Workstation is an instance
of Workstation class.

00:02:30.920 --> 00:02:34.280 align:middle
Likewise, Object
is an instance of Object class.

00:02:34.680 --> 00:02:36.160 align:middle
If I message

00:02:36.360 --> 00:02:37.880 align:middle
the object aWorkstation,

00:02:39.680 --> 00:02:42.880 align:middle
the lookup algorithm searches
the aWorkstation class.

00:02:43.400 --> 00:02:45.640 align:middle
Then it goes up
through superclasses

00:02:45.800 --> 00:02:48.240 align:middle
until it finds
a matching method.

00:02:48.720 --> 00:02:51.920 align:middle
The mechanism
is exactly the same

00:02:52.440 --> 00:02:56.320 align:middle
when I message
the Workstation class.

00:02:56.720 --> 00:03:00.440 align:middle
For example, if I send the message
"new"

00:03:00.960 --> 00:03:04.080 align:middle
to Workstation,
the lookup algorithm

00:03:04.280 --> 00:03:08.280 align:middle
searches Workstation class
for a method called "new."

00:03:08.920 --> 00:03:11.160 align:middle
If it finds it here,
it executes it.

00:03:11.400 --> 00:03:14.960 align:middle
If it does not find a match,
it moves up to the superclass,

00:03:15.120 --> 00:03:17.880 align:middle
and then up
to the next superclass.

00:03:19.000 --> 00:03:21.760 align:middle
And so on.
This hierarchy continues.

00:03:22.960 --> 00:03:26.880 align:middle
I'll leave you with this slide
summing up messaging

00:03:27.040 --> 00:03:30.560 align:middle
to standard objects
and classes as standard objects.

00:03:31.800 --> 00:03:33.120 align:middle
Here's what to remember:

00:03:33.480 --> 00:03:36.360 align:middle
A class is an object
like any other.

00:03:37.040 --> 00:03:40.680 align:middle
Messages can be sent to objects,
and therefore to classes.

00:03:41.480 --> 00:03:45.640 align:middle
The lookup mechanism
is exactly the same in both cases.

00:03:47.400 --> 00:03:51.280 align:middle
It starts searching
in the class of the receiver,

00:03:51.680 --> 00:03:55.400 align:middle
and then searches each superclass
in the inheritance chain

00:03:55.760 --> 00:03:58.120 align:middle
until it finds a matching method.

00:03:58.600 --> 00:04:02.880 align:middle
You'll learn more about metaclasses
in "Understanding Metaclasses."

