1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
<HTML>
<HEAD>
<TITLE>Brief Guide to CLOS: Multiple inheritance</TITLE>
</HEAD>
<BODY>
<A HREF="CLOS-guide-4.html"><IMG SRC="prev.gif" ALT="Previous"></A>
<A HREF="CLOS-guide-6.html"><IMG SRC="next.gif" ALT="Next"></A>
<A HREF="CLOS-guide.html#toc5"><IMG SRC="toc.gif" ALT="Contents"></A>
<HR>
<H2><A NAME="s5">5. Multiple inheritance</A></H2>
<P>A class can have more than one superclass. With single inheritance
(one superclass), it's easy to order the superclasses from most to
least specific. This is the rule:</P>
<P>
<UL>
<LI>Rule 1: Each class is more specific than its superclasses.
In multiple inheritance this is harder. Suppose we have
<CODE>(defclass a (b c) ...)</CODE>
Class <CODE>A</CODE> is more specific than <CODE>B</CODE> or <CODE>C</CODE> (for instances of
<CODE>A</CODE>), but what if
something (an <CODE>:INITFORM</CODE>, or a method) is specified by
<CODE>B</CODE> and <CODE>C</CODE>? Which
overrides the other? The rule in <CODE>CLOS</CODE> is that the superclasses listed
earlier are more specific than those listed later. So:
</LI>
<LI>Rule 2: For a given class, superclasses listed earlier are more
specific than those listed later.
These rules are used to compute a linear order for a class and all its
superclasses, from most specific to least specific. This order is the
"class precedence list" of the class.
The two rules are not always enough to determine a unique order,
however, so <CODE>CLOS</CODE> has an algorithm for breaking ties. This ensures
that all implementations always produce the same order, but it's
usually considered a bad idea for programmers to rely on exactly
what the order is. If the order for some superclasses is important,
it can be expressed directly in the class definition.</LI>
</UL>
</P>
<HR>
<A HREF="CLOS-guide-4.html"><IMG SRC="prev.gif" ALT="Previous"></A>
<A HREF="CLOS-guide-6.html"><IMG SRC="next.gif" ALT="Next"></A>
<A HREF="CLOS-guide.html#toc5"><IMG SRC="toc.gif" ALT="Contents"></A>
</BODY>
</HTML>
|