127 lines
8.7 KiB
HTML
127 lines
8.7 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.2. Classes</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<meta name="description" value=" Classes">
|
|
<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=tex2html4946 HREF="node264.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html4944 HREF="node261.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html4938 HREF="node262.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html4948 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html4949 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html4947 HREF="node264.html"> Defining Classes</A>
|
|
<B>Up:</B> <A NAME=tex2html4945 HREF="node261.html"> Programmer Interface Concepts</A>
|
|
<B> Previous:</B> <A NAME=tex2html4939 HREF="node262.html"> Error Terminology</A>
|
|
<HR> <P>
|
|
<H2><A NAME=SECTION003212000000000000000>28.1.2. Classes</A></H2>
|
|
<P>
|
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
|
<A NAME=ClassesSECTION>A</A>
|
|
<i>class</i> is an object that determines the structure and behavior
|
|
of a set of other objects, which are called its <i>instances</i>.
|
|
<P>
|
|
A class can inherit structure and behavior from other classes.
|
|
A class whose definition refers to other classes for the purpose of
|
|
inheriting from them is said to be a <i>subclass</i> of each of
|
|
those classes. The classes that are designated for purposes of
|
|
inheritance are said to be <i>superclasses</i>
|
|
of the inheriting class.
|
|
<P>
|
|
A class can have a <i>name</i>. The function <tt>class-name</tt> takes a
|
|
class object and returns its name. The name of an anonymous class is
|
|
<tt>nil</tt>. A symbol can <i>name</i> a class. The function
|
|
<tt>find-class</tt> takes a symbol and returns the class that the symbol
|
|
names. A class has a <i>proper name</i> if the name is a symbol
|
|
and if the name of the class
|
|
names that class. That is, a class <i>C</i> has the <i>proper
|
|
name</i> <i>S</i> if <i>S</i> <b>=</b> <tt>(class-name <i>C</i>)</tt> and <i>C</i> <b>=</b> <tt>(find-class
|
|
<i>S</i>)</tt>. Notice that it is possible for <tt>(find-class <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43319.gif">)</tt>
|
|
<b>=</b> <tt>(find-class <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43323.gif">)</tt> and <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43325.gif">.
|
|
If <i>C</i> <b>=</b> <tt>(find-class <i>S</i>)</tt>, we say that <i>C</i> is the <i>class named</i>
|
|
<i>S</i>.
|
|
<P>
|
|
A class <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> is a <i>direct superclass</i> of a class
|
|
<IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43591.gif"> if <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43591.gif"> explicitly designates <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> as a
|
|
superclass in its definition. In this case, <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43591.gif"> is a <i>direct subclass</i> of <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif">. A class <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43341.gif"> is a <i>superclass</i> of a class <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> if there exists a series of
|
|
classes <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43345.gif">
|
|
such that <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43347.gif"> is a
|
|
direct superclass of <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43425.gif"> for <b>1 <i>i</i> < <i>n</i></b>. In this case,
|
|
<IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> is a <i>subclass</i> of <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43341.gif">. A class is
|
|
considered neither a superclass nor a subclass of itself. That is, if
|
|
<IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> is a superclass of <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43591.gif">, then <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43361.gif">. The set of classes consisting of some given
|
|
class <i>C</i> along with all of its superclasses is called ``<i>C</i> and its
|
|
superclasses.''
|
|
<P>
|
|
Each class has a <i>class precedence list</i>, which is a total ordering
|
|
on the set of the given class and its superclasses. The total ordering
|
|
is expressed as a list ordered from most specific to least specific.
|
|
The class precedence list is used in several ways. In general, more
|
|
specific classes can <i>shadow</i>, or override, features that would
|
|
otherwise be inherited from less specific classes. The method selection
|
|
and combination process uses the class precedence list to order methods
|
|
from most specific to least specific.
|
|
<P>
|
|
When a class is defined, the order in which its direct superclasses
|
|
are mentioned in the defining form is important. Each class has a
|
|
<i>local precedence order</i>, which is a list consisting of the
|
|
class followed by its direct superclasses in the order mentioned
|
|
in the defining form.
|
|
<P>
|
|
A class precedence list is always consistent with the local precedence
|
|
order of each class in the list. The classes in each local precedence
|
|
order appear within the class precedence list in the same order. If
|
|
the local precedence orders are inconsistent with each other, no class
|
|
precedence list can be constructed, and an error is signaled.
|
|
The class precedence list and its computation is discussed
|
|
in section <A HREF="node274.html#DeterminingtheClassPrecedenceListSECTION">28.1.5</A>.
|
|
<P>
|
|
Classes are organized into a <i>directed acyclic graph</i>. There are
|
|
two distinguished classes, named <tt>t</tt> and <tt>standard-object</tt>.
|
|
The class named <tt>t</tt> has no superclasses. It is a superclass of
|
|
every class except itself. The class named <tt>standard-object</tt> is
|
|
an instance of the class <tt>standard-class</tt> and is a superclass of
|
|
every class that is an instance of <tt>standard-class</tt> except itself.
|
|
<P>
|
|
There is a mapping from the Common Lisp Object System class space into
|
|
the Common Lisp type space. Many of the standard Common Lisp types
|
|
have a corresponding
|
|
class that has the same name as the type. Some Common Lisp types do
|
|
not have a corresponding class. The integration of the type and class
|
|
systems is discussed in section <A HREF="node273.html#IntegratingTypesandClassesSECTION">28.1.4</A>.
|
|
<P>
|
|
Classes are represented by objects that are themselves
|
|
instances of classes. The class of the class of an object is termed
|
|
the <i>metaclass</i> of that object. When no misinterpretation is
|
|
possible, the term <i>metaclass</i> will be used to refer to a class
|
|
that has instances that are themselves classes. The metaclass
|
|
determines the form of inheritance used by the classes that are its
|
|
instances and the representation of the instances of those classes.
|
|
The Common Lisp Object System provides a default metaclass, <tt>standard-class</tt>, that is
|
|
appropriate for most programs. The meta-object protocol provides
|
|
mechanisms for defining and using new metaclasses.
|
|
<P>
|
|
Except where otherwise specified, all classes mentioned in this
|
|
chapter are instances of the class <tt>standard-class</tt>, all generic
|
|
functions are instances of the class <tt>standard-generic-function</tt>,
|
|
and all methods are instances of the class <tt>standard-method</tt>.
|
|
<P>
|
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
|
<HR>
|
|
<UL>
|
|
<LI> <A NAME=tex2html4950 HREF="node264.html#SECTION003212100000000000000"> Defining Classes</A>
|
|
<LI> <A NAME=tex2html4951 HREF="node265.html#SECTION003212200000000000000"> Creating Instances of Classes</A>
|
|
<LI> <A NAME=tex2html4952 HREF="node266.html#SECTION003212300000000000000"> Slots</A>
|
|
<LI> <A NAME=tex2html4953 HREF="node267.html#SECTION003212400000000000000"> Accessing Slots</A>
|
|
</UL>
|
|
<BR> <HR><A NAME=tex2html4946 HREF="node264.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html4944 HREF="node261.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html4938 HREF="node262.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html4948 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html4949 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html4947 HREF="node264.html"> Defining Classes</A>
|
|
<B>Up:</B> <A NAME=tex2html4945 HREF="node261.html"> Programmer Interface Concepts</A>
|
|
<B> Previous:</B> <A NAME=tex2html4939 HREF="node262.html"> Error Terminology</A>
|
|
<HR> <P>
|
|
<HR>
|
|
<P><ADDRESS>
|
|
AI.Repository@cs.cmu.edu
|
|
</ADDRESS>
|
|
</BODY>
|