Goops Manual (original) (raw)

Node:Metaclass, Next:Class Precedence List, Up:Terminology


3.1.2.1 Metaclass

A metaclass is the class of an object which represents a GOOPS class. Put more succinctly, a metaclass is a class's class.

Most GOOPS classes have the metaclass <class> and, by default, any new class that is created using define-class has the metaclass <class>.

But what does this really mean? To find out, let's look in more detail at what happens when a new class is created using define-class:

(define-class () . slots)

GOOPS actually expands the define-class form to something like this

(define (class () . slots))

and thence to

(define (make #:supers (list ) #:slots slots))

In other words, the value of <my-class> is in fact an instance of the class <class> with slot values specifying the superclasses and slot definitions for the class <my-class>. (#:supersand #:slots are initialization keywords for the dsupersand dslots slots of the <class> class.)

In order to take advantage of the full power of the GOOPS metaobject protocol (see MOP Specification), it is sometimes desirable to create a new class with a metaclass other than the default<class>. This is done by writing:

(define-class () slot ... #:metaclass )

GOOPS expands this to something like:

(define (make #:supers (list ) #:slots slots))

In this case, the value of <my-class2> is an instance of the more specialized class <my-metaclass>. Note that<my-metaclass> itself must previously have been defined as a subclass of <class>. For a full discussion of when and how it is useful to define new metaclasses, see MOP Specification.

Now let's make an instance of <my-class2>:

(define my-object (make ...))

All of the following statements are correct expressions of the relationships between my-object, <my-class2>,<my-metaclass> and <class>.