A defclass is a construct for specifying the properties (slots) and behavior (message-handlers) of a class of objects. A defclass consists of five elements: 1) a name, 2) a list of superclasses from which the new class inherits slots and message-handlers, 3) a specifier saying whether or not the creation of direct instances of the new class is allowed, 4) a specifier saying whether or not instances of this class can match object patterns on the LHS of rules and 5) a list of slots specific to the new class. All user-defined classes must inherit from at least one class, and to this end COOL provides predefined system classes for use as a base in the derivation of new classes.
Any slots explicitly given in the defclass override those gotten from inheritance. COOL applies rules to the list of superclasses to generate a class precedence list (see section 9.3.1) for the new class. Facets (see section 9.3.3) further describe slots. Some examples of facets include: default value, cardinality, and types of access allowed.
Syntax
Defaults are outlined.
(defclass <name> [<comment>]
(is-a <superclass-name>+)
[<role>]
[<pattern-match-role>]
<slot>*
<handler-documentation>*)
<role> ::= (role concrete | abstract)
<pattern-match-role>
::= (pattern-match reactive | non-reactive)
<slot> ::= (slot <name> <facet>*) |
(single-slot <name> <facet>*) |
(multislot <name> <facet>*)
<facet> ::= <default-facet> | <storage-facet> |
<access-facet> | <propagation-facet> |
<source-facet> | <pattern-match-facet> |
<visibility-facet> | <create-accessor-facet>
<override-message-facet> | <constraint-attributes>
<default-facet> ::=
(default ?DERIVE | ?NONE | <expression>*) |
(default-dynamic <expression>*)
<storage-facet> ::= (storage local | shared)
<access-facet>
::= (access read-write | read-only | initialize-only)
<propagation-facet> ::= (propagation inherit | no-inherit)
<source-facet> ::= (source exclusive | composite)
<pattern-match-facet>
::= (pattern-match reactive | non-reactive)
<visibility-facet> ::= (visibility private | public)
<create-accessor-facet>
::= (create-accessor ?NONE | read | write | read-write)
<override-message-facet>
::= (override-message ?DEFAULT | <message-name>)
<handler-documentation>
::= (message-handler <name> [<handler-type>])
<handler-type> ::= primary | around | before | after
Redefining an existing class deletes the current subclasses and
all associated message-handlers. An error will occur if instances
of the class or any of its subclasses exist.
9.3.1 Multiple Inheritance
9.3.2 Class Specifiers
9.3.3 Slots
9.3.4 Message-handler Documentation