1 A minimal reflective class-based kernel

The difference between classes and objects has been repeatedly emphasized. In the view presented here, these concepts belong to different worlds: the program text only contains classes; at run-time, only objects exist. This is not the only approach. One of the subcultures of object-oriented programming, influenced by Lisp and exemplified by Smalltalk, views classes as objects themselves, which still have an existence at run-time. — B. Meyer, Object-Oriented Software Construction Meye88b

As this quote expresses it, there is a realm where classes are true objects, instances of other classes. In such systems as Smalltalk, Pharo Blac09a, CLOS Stee90a, classes are described by other classes and form often reflective architectures each one describing the previous level. In this chapter, we will explore a minimal reflective class-based kernel, inspired by ObjVlisp. In the following chapter, you will implement step by step such a kernel with less than 30 methods.

1.1 ObjVlisp inspiration

ObjVlisp was published for the first time in 1987 when the foundation of object-oriented programming was still emerging Coin87a. ObjVlisp has explicit metaclasses and supports metaclass reuse. It was inspired by the kernel of Smalltalk-78. The IBM SOM-DSOM kernel is similar to ObjVLisp while implemented in C++ Form99a. ObjVlisp is a subset of the reflective kernel of CLOS (Common Lisp Object System) since CLOS reifies instance variables, generic functions, and method combinations. It is the equivalent of the Closette implementation Kicz91a. In comparison to ObjVlisp, Smalltalk, and Pharo have implicit metaclasses and no metaclass reuse except by basic inheritance. However, they are more stable as explained by Bouraqadi et al Bour98a.

Studying this kernel is really worth it since it has the following properties:

Just remember that this kernel is self-described. We will start to explain some aspects, but since everything is linked, you may have to read the chapter twice to fully get it.

1.2 ObjVLisp's six postulates

The original ObjVlisp kernel is defined by six postulates Coin87a. Some of them look a bit dated by modern standards, and the 6th postulate is simply wrong as we will explain later (a solution is simple to design and implement).

Here are the six postulates as stated in the paper for the sake of historical perspective.

1.3 Kernel overview

If you do not fully grasp the following overview, don't worry. This full chapter is here to make sure that you will understand it. Let us get started.

Contrary to a real uniform language kernel, ObjVlisp does not consider arrays, booleans, strings, numbers or any other elementary objects as part of the kernel as this is the case in a real bootstrap such as the one of Pharo. ObjVLisp's kernel focuses on understanding Class/Object core relationships.

Figure 1.1 shows the two core classes of the kernel:

The ObjVlisp kernel: a minimal class-based kernel.
Figure 1.1 The ObjVlisp kernel: a minimal class-based kernel.

Figure 1.2 shows that the class Workstation is an instance of the class Class since it is a class and it inherits from Object the default behavior objects should exhibit. The class WithSingleton is an instance of the class Class but in addition, it inherits from Class, since this is a metaclass: its instances are classes. As such, it changes the behavior of classes. The class SpecialWorkstation is an instance of the class WithSingleton and inherits from Workstation, since its instances exhibit the same behavior as Workstation.

The kernel with specialized metaclasses.
Figure 1.2 The kernel with specialized metaclasses.

The two diagrams 1.1 and 1.2 will be explained step by step throughout this chapter.

The key point of understanding such a reflective architecture is that message passing always looks up methods in the class of the receiver of the message and then follows the inheritance chain (See Figure 1.3).

Understanding metaclasses using message passing.
Figure 1.3 Understanding metaclasses using message passing.

Figure 1.3 illustrates two main cases:

1.4 Conclusion

ObjVLisp is a minimal kernel with its two main classes. It uses the infrastructure of the underlying language (integers, strings, booleans...). When the language is fully reflective such as Pharo all such infrastructure has to be defined at the same level as the class Object and Class but the model principles stay the same.