Next: , Previous: Introduction, Up: Top

3 Building Classes

First off, please note that this manual cannot serve as a complete introduction to object oriented programming and generic functions in LISP. Although EIEIO is not a complete CLOS implementation and also differs from CLOS in several aspects, it follows the same basic concepts. Therefore, it is highly recommended to learn these from a textbook or tutorial first, especially if you only know OOP from languages like C++ or Java. If on the other hand you are already familiar with CLOS, you should be aware that EIEIO does not implement the full CLOS specificiation and also differs in some other aspects (See Introduction, and CLOS compatibility).

A class is a definition for organizing data and methods together. An EIEIO class has structures similar to the classes found in other object-oriented (OO) languages.

To create a new class, use the defclass macro:

— Macro: defclass class-name superclass-list slot-list &rest options-and-doc

Create a new class named class-name. The class is represented by a self-referential symbol with the name class-name. EIEIO stores the structure of the class as a symbol property of class-name (see Symbol Components).

The class-name symbol's variable documentation string is a modified version of the doc string found in options-and-doc. Each time a method is defined, the symbol's documentation string is updated to include the methods documentation as well.

The parent classes for class-name is superclass-list. Each element of superclass-list must be a class. These classes are the parents of the class being created. Every slot that appears in each parent class is replicated in the new class.

If two parents share the same slot name, the parent which appears in the superclass-list first sets the tags for that slot. If the new class has a slot with the same name as the parent, the new slot overrides the parent's slot.

When overriding a slot, some slot attributes cannot be overridden because they break basic OO rules. You cannot override :type or :protection.

Whenever defclass is used to create a new class, two predicates are created for it, named CLASS-NAME-p and CLASS-NAME-child-p:

— Function: CLASS-NAME-p object

Return t if OBJECT is of the class CLASS-NAME.

— Function: CLASS-NAME-child-p object

Return t if OBJECT is of the class CLASS-NAME, or is of a subclass of CLASS-NAME.

— Variable: eieio-error-unsupported-class-tags

If non-nil, defclass signals an error if a tag in a slot specifier is unsupported.

This option is here to support programs written with older versions of EIEIO, which did not produce such errors.