The class above had no superclass. That's why there was a
"defclass person". Actually, this means it
has one superclass: the
When there are superclasses, a subclass can specify a slot that has already been specified for a superclass. When this happens, the information in slot options has to be combined. For the slot options listed above, either the option in the subclass overrides the one in the superclass or there is a union:
This is what you should expect. The subclass can change the
default initial value by overriding the
:INITFORM, and can add
to the initargs and accessors.
However, the "union" for accessor is just a consequence of how generic functions work. If they can apply to instances of a class C, they can also apply to instances of subclasses of C.
(Accessor functions are generic. This may become clearer once generic functions are discussed, below.)
Here are some subclasses:
<cl> (defclass teacher (person) ((subject :accessor teacher-subject :initarg :subject))) #<clos:standard-class teacher @ #x7cf796> #<cl> (defclass maths-teacher (teacher) ((subject :initform "Mathematics"))) #<clos:standard-class maths-teacher @ #x7d94be> <cl> (setq p2 (make-instance 'maths-teacher :name 'john :age 34)) #<maths-teacher @ #x7dcc66> <cl> (describe p2) #<maths-teacher @ #x7dcc66>; is an instance of class #<clos:standard-class maths-teacher @ #x7d94be>: The following slots have :INSTANCE allocation: age 34 name john subject "Mathematics"
Note that classes print like
#<clos:standard-class maths-teacher @ #x7d94be>.
#<...> notation usually has the form
#<class-of-the-object ... more information ...>
So an instance of maths-teacher prints as
The notation for the classes above indicates that they are
DEFCLASS defines standard classes.
DEFSTRUCT defines structure classes.