Next: , Previous: , Up: The Metaobject Protocol   [Contents][Index]


8.11.5 Class Definition Protocol

Here is a summary diagram of the syntax, procedures and generic functions that may be involved in class definition.

define-class (syntax)

Wherever a step above is marked as “generic”, it can be customized, and the detail shown below it is only “correct” insofar as it describes what the default method of that generic function does. For example, if you write an initialize method, for some metaclass, that does not call next-method and does not call compute-cpl, then compute-cpl will not be called when a class is defined with that metaclass.

A (define-class ...) form (see Class Definition) expands to an expression which

syntax: class name (super …) slot-definition … class-option …

Return a newly created class that inherits from supers, with direct slots defined by slot-definitions and class-options. For the format of slot-definitions and class-options, see define-class.

class expands to an expression which

procedure: make-class supers slots class-option …

Return a newly created class that inherits from supers, with direct slots defined by slots and class-options. For the format of slots and class-options, see define-class, except note that for make-class, slots is a separate list of slot definitions.

make-class

procedure: ensure-metaclass supers env

Return a metaclass suitable for a class that inherits from the list of classes in supers. The returned metaclass is the union by inheritance of the metaclasses of the classes in supers.

In the simplest case, where all the supers are straightforward classes with metaclass <class>, the returned metaclass is just <class>.

For a more complex example, suppose that supers contained one class with metaclass <operator-class> and one with metaclass <foreign-object-class>. Then the returned metaclass would be a class that inherits from both <operator-class> and <foreign-object-class>.

If supers is the empty list, ensure-metaclass returns the default GOOPS metaclass <class>.

GOOPS keeps a list of the metaclasses created by ensure-metaclass, so that each required type of metaclass only has to be created once.

The env parameter is ignored.

generic: make metaclass initarg …

metaclass is the metaclass of the class being defined, either taken from the #:metaclass class option or computed by ensure-metaclass. The applied method must create and return the fully initialized class metaobject for the new class definition.

The (make metaclass initarg …) invocation is a particular case of the instance creation protocol covered in the previous section. It will create an class metaobject with metaclass metaclass. By default, this metaobject will be initialized by the initialize method that is specialized for instances of type <class>.

The initialize method for classes (signature (initialize <class> initargs)) calls the following generic functions.


Next: , Previous: , Up: The Metaobject Protocol   [Contents][Index]