Really Understanding Class Methods
Damien Cassou, Stéphane Ducasse and Luc Fabresse
http://stephane.ducasse.free.fr
What You Will Learn
- There is only one lookup algorithm
- it works for both instance and class methods
- Class methods are not Java-like static methods
There is Only One Lookup
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
Sending a Message
Sending a message is a two-step process:
- look up the method matching the message
- execute this method on the receiver
Sending a Message to a Class
Sending a message to Counter
(a class)
- go to the class of the class (
Counter class
)
- follow the inheritance chain
- apply the found method to the receiver: the class
Counter
A Class is an Instance
A class is an instance of another class (called a metaclass)
Counter
is the unique instance of the class Counter class
- A metaclass is just one class whose instances are classes
Counter class
is automatically created after Counter
- The class of class
XXX
is named XXX class
Browsing two Classes
The browser can edit two classes: a class and its class
What You Should Know
- A class is an object
- A class can receive messages
- A class is an instance of a class, called a metaclass
- Method lookup works the same
- More during the lecture Understanding Metaclasses
/