next up previous contents
Next: The pattern of Up: No Title Previous: Caching of Effective

Metaclasses

 

For several reasons it is attractive and interesting to represent classes as objects that are on equal footing with the objects that are instantiated from the classes.

  1. It is possible to instantiate a class by sending a message to the object, which represents the class.

  2. It is natural to represent the characteristics of the class in the state variables (class variables) of the object that represents the class. In that way the characteristics of a class are readily available as data to the surrounding system.

Point number two provides for so-called metaprogramming, which is particularly important when making tools in the programming environment.

The class of an object, which represents a class, is usually called a metaclass. In this section I will discuss how to simulate metaclasses and how to simulate classes as objects. I will also demonstrate how to simulate the upper part of the class hierarchy, which ties the whole object-oriented framework together. Finally, I will show how to instantiate classes via message passing to the object, which represents the class.





Kurt Noermark
Wed Mar 6 10:30:05 MET 1996