manpagez: man pages & more
info goops
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.3.1 Class definition

A new class is defined with the define-class(1) macro. The syntax of define-class is close to CLOS defclass:

 
(define-class class (superclass …)
   slot-descriptionclass-option …)

Class options will not be discussed in this tutorial. The list of superclasses specifies which classes to inherit properties from class (see Inheritance for more details). A slot-description gives the name of a slot and, eventually, some “properties” of this slot (such as its initial value, the function which permit to access its value, …). Slot descriptions will be discussed in Slot description.

As an example, let us define a type for representation of complex numbers in terms of real numbers. This can be done with the following class definition:

 
(define-class  <complex> (<number>)
   r i)

This binds the variable <complex>(2) to a new class whose instances contain two slots. These slots are called r an i and we suppose here that they contain respectively the real part and the imaginary part of a complex number. Note that this class inherits from <number> which is a pre-defined class. (<number> is the direct super class of the pre-defined class <complex> which, in turn, is the super class of <real> which is the super of <integer>.)(3).


© manpagez.com 2000-2024
Individual documents may contain additional copyright information.