1
0
Fork 0
cl-sites/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node270.html
2023-10-25 11:23:21 +02:00

121 lines
8 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE>28.1.3.2. Inheritance of Slots and Slot Options</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Inheritance of Slots and Slot Options">
<meta name="keywords" value="clm">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<b>Common Lisp the Language, 2nd Edition</b>
<BR> <HR><A NAME=tex2html5036 HREF="node271.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html5034 HREF="node268.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html5028 HREF="node269.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html5038 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html5039 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html5037 HREF="node271.html"> Inheritance of Class </A>
<B>Up:</B> <A NAME=tex2html5035 HREF="node268.html"> Inheritance</A>
<B> Previous:</B> <A NAME=tex2html5029 HREF="node269.html"> Inheritance of Methods</A>
<HR> <P>
<H3><A NAME=SECTION003213200000000000000>28.1.3.2. Inheritance of Slots and Slot Options</A></H3>
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
<A NAME=InheritanceofSlotsandSlotOptionsSECTION>The</A>
set of names of all slots accessible in an instance of a class
<i>C</i> is the union of the sets of names of slots defined by <i>C</i> and its
superclasses. The <i>structure</i> of an instance is the set of names
of local slots in that instance.
<P>
In the simplest case, only one class among <i>C</i> and its superclasses
defines a slot with a given slot name. If a slot is defined by a
superclass of <i>C</i>, the slot is said to be <i>inherited</i>. The characteristics of the slot are determined by the
slot specifier of the defining class. Consider the defining class for
a slot <i>S</i>. If the value of the <tt>:allocation</tt> slot
option is <tt>:instance</tt>, then <i>S</i> is a local slot and each instance
of <i>C</i> has its own slot named <i>S</i> that stores its own value. If the
value of the <tt>:allocation</tt> slot option is <tt>:class</tt>, then <i>S</i>
is a shared slot, the class that defined <i>S</i> stores the value, and all
instances of <i>C</i> can access that single slot. If the
<tt>:allocation</tt> slot option is omitted, <tt>:instance</tt> is used.
<P>
In general, more than one class among <i>C</i> and its superclasses can
define a slot with a given name. In such cases, only one slot with
the given name is accessible in an instance of <i>C</i>, and
the characteristics of that slot are a combination of the several slot
specifiers, computed as follows:
<P>
<UL><LI> All the slot specifiers for a given slot name are ordered
from most specific to least specific, according to the order in <i>C</i>'s
class precedence list of the classes that define them. All references
to the specificity of slot specifiers immediately following refer to this
ordering.
<P>
<LI> The allocation of a slot is controlled by the most specific
slot specifier. If the most specific slot specifier does not contain an
<tt>:allocation</tt> slot option, <tt>:instance</tt> is used. Less specific
slot specifiers do not affect the allocation.
<P>
<LI> The default initial value form for a
slot is the value of the <tt>:initform</tt> slot option in the most
specific slot specifier that contains one. If no slot specifier
contains an <tt>:initform</tt> slot option, the slot has no default
initial value form.
<P>
<LI> The contents of a slot will always be of type
<tt>(and <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43475.gif"> <b>...</b> <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43367.gif">)</tt>
where <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43369.gif"> are
the values of the <tt>:type</tt> slot options contained in all of the slot
specifiers. If no slot specifier contains the <tt>:type</tt> slot option, the
contents of the slot will always be of type <tt>t</tt>. The result
of attempting to store in a slot
a value that does not satisfy the type of the slot is undefined.
<P>
<LI> The set of initialization arguments that initialize a given
slot is the union of the initialization arguments declared in the
<tt>:initarg</tt> slot options in all the slot specifiers.
<P>
<LI> The documentation string for a slot is the value of the
<tt>:documentation</tt> slot option in the most specific slot specifier
that contains one. If no slot specifier contains a
<tt>:documentation</tt> slot option, the slot has no documentation string.
</UL>
<P>
A consequence of the allocation rule is that a shared slot can be
shadowed. For example, if a class <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> defines a slot named <i>S</i>
whose value for the <tt>:allocation</tt> slot option is <tt>:class</tt>,
that slot is accessible in instances of <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> and all of its
subclasses. However, if <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43591.gif"> is a subclass of <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> and also
defines a slot named <i>S</i>, <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif">'s slot is not shared
by instances of <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43591.gif"> and its subclasses. When a class
<IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> defines a shared slot, any subclass <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43591.gif"> of <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> will share this single slot unless the <tt>defclass</tt> form for
<IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43591.gif"> specifies a slot of the same name or there is a superclass
of <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43591.gif"> that precedes <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> in the class precedence list of
<IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43591.gif"> that defines a slot of the same name.
<P>
A consequence of the type rule is that the value of a slot satisfies
the type constraint of each slot specifier that contributes to that
slot. Because the result of attempting to store in a slot a value
that does not satisfy the type constraint for the slot is undefined,
the value in a slot might fail to satisfy its type constraint.
<P>
The <tt>:reader</tt>, <tt>:writer</tt>, and <tt>:accessor</tt> slot options
create methods rather than define the characteristics of a slot.
Reader and writer methods are inherited in the sense described in
section <A HREF="node269.html#InheritanceofMethodsSECTION">28.1.3.1</A>.
<P>
Methods that access slots use only the name of the slot and the type
of the slot's value. Suppose a superclass provides a method that
expects to access a shared slot of a given name, and a subclass defines
a local slot with the same name. If the method provided by the
superclass is used on an instance of the subclass, the method accesses
the local slot.
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
<BR> <HR><A NAME=tex2html5036 HREF="node271.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html5034 HREF="node268.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html5028 HREF="node269.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html5038 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html5039 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html5037 HREF="node271.html"> Inheritance of Class </A>
<B>Up:</B> <A NAME=tex2html5035 HREF="node268.html"> Inheritance</A>
<B> Previous:</B> <A NAME=tex2html5029 HREF="node269.html"> Inheritance of Methods</A>
<HR> <P>
<HR>
<P><ADDRESS>
AI.Repository@cs.cmu.edu
</ADDRESS>
</BODY>