When compiling an object, Logtalk distinguishes prototypes from instance or classes by examining the object relations. If an object instantiates and/or specializes another object, then it is compiled as an instance or class, otherwise it is compiled as a prototype. A consequence of this is that, in order to work with instance or classes, we always have to define root objects for the instantiation and specialization hierarchies (however, we are not restricted to a single hierarchy). The best solution is often to define a reflective class-based system <ahref="../bibliography.html#Maes87">[Maes 87]</a>, where every class is also an object and, as such, an instance of some class.
</p>
<p>
In this example, we are going to define the basis for a reflective class-based system, based on an extension of the ideas presented in <ahref="../bibliography.html#Cointe87">[Cointe 87]</a>. This extension provides, along with root objects for the instantiation and specialization hierarchies, explicit support for abstract classes <ahref="../bibliography.html#Moura94">[Moura 94]</a>.
We will start by defining three classes: <code>object</code>, <code>abstract_class</code>, and <code>class</code>. The class <code>object</code> will contain all predicates common to all objects. It will be the root of the inheritance graph:
The class <code>abstract_class</code> specializes <code>object</code> by adding predicates common to all classes. It will be the default meta-class for abstract classes:
The class <code>class</code> specializes <code>abstract_class</code> by adding predicates common to all instantiable classes. It will be the root of the instantiation graph and the default meta-class for instantiable classes:
Note that all three objects are instances of class <code>class</code>. The instantiation and specialization relationships are chosen so that each object may use the predicates defined in itself and in the other two objects, with no danger of method lookup endless loops.
<li>The distinction between abstract classes and instantiable classes is an operational one, depending on the class inherited methods. A class is instantiable if inherits methods for creating instances. Conversely, a class is abstract if does not inherit any instance creation method.</li>