Goops Manual (original) (raw)
Node:Basic Class Definition, Next:Class Options, Up:Defining New Classes
3.2.1 Basic Class Definition
New classes are defined using the define-class
syntax, with arguments that specify the classes that the new class should inherit from, the direct slots of the new class, and any required class options.
define-class name (super ...) slot-definition ... . options | syntax |
---|
Define a class called name that inherits from supers, with direct slots defined by slot-definitions and class optionsoptions. The newly created class is bound to the variable namename in the current environment.
Each slot-definition is either a symbol that names the slot or a list,
(slot-name-symbol . slot-options)
where slot-name-symbol is a symbol and slot-options is a list with an even number of elements. The even-numbered elements ofslot-options (counting from zero) are slot option keywords; the odd-numbered elements are the corresponding values for those keywords.
options is a similarly structured list containing class option keywords and corresponding values.
The standard GOOPS class and slot options are described in the following subsections: see Class Options and Slot Options.
Example 1. Define a class that combines two pre-existing classes by inheritance but adds no new slots.
(define-class ( ))
Example 2. Define a regular-polygon
class with slots for side length and number of sides that have default values and can be accessed via the generic functions side-length
and num-sides
.
(define-class () (sl #:init-value 1 #:accessor side-length) (ns #:init-value 5 #:accessor num-sides))
Example 3. Define a class whose behavior (and that of its instances) is customized via an application-defined metaclass.
(define-class () (s #:init-value #f #:accessor state) ... #:metaclass )