page114.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 91 行
HTML
91 行
<HTML><HEAD><TITLE>Class Hierarchy</TITLE></HEAD><BODY bgcolor="#FFFFFF"> <a href="../index.html" target="_top"><img src="../icons/usins.gif" alt="Logo" align=right></a><b>Data Structures and Algorithms with Object-Oriented Design Patterns in Python</b><br><A NAME="tex2html2529" HREF="page115.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2527" HREF="page113.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2521" HREF="page113.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html2531" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION005210000000000000000">Class Hierarchy</A></H2><P>The Python class hierarchy which is used to representthe basic repertoire of abstract data types is shownin Figure <A HREF="page114.html#figclasses"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.Two kinds of classes are shown in Figure <A HREF="page114.html#figclasses"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>;<em>abstract Python classes</em><A NAME=4335> </A>,which look like this <IMG WIDTH=85 HEIGHT=16 ALIGN=BOTTOM ALT="tex2html_wrap60661" SRC="img641.gif" >,and <em>concrete Python classes</em><A NAME=4338> </A>,which look like this <IMG WIDTH=89 HEIGHT=16 ALIGN=BOTTOM ALT="tex2html_wrap60663" SRC="img642.gif" >.Arrows in the figure indicate the<em>specializes</em><A NAME=4341> </A> relation between classes;an arrow points from a derived classto the base class from which it is derived.<P><P><A NAME="4346"> </A><A NAME="figclasses"> </A> <IMG WIDTH=576 HEIGHT=793 ALIGN=BOTTOM ALT="figure4342" SRC="img643.gif" ><BR><STRONG>Figure:</STRONG> Object class hierarchy.<BR><P><P>The distinction between an<em>abstract class</em><A NAME=4350> </A>and a<em>concrete class</em><A NAME=4352> </A>is purely one of convention.These concepts are not built into the Python language.Nevertheless,it is possible to write Python programs in a waythat makes it clear that a class is an abstract class.<P>An <em>abstract class</em><A NAME=4354> </A> isa class which defines only part of an implementation.Consequently, it does not make sense to create object instancesof abstract classes.By convention, an abstract class may contain zero or more<em>abstract methods</em><A NAME=4356> </A>or<em>abstract properties</em><A NAME=4358> </A>.As with classes,the distinction between abstract methods or propertiesand concrete methods or properties is purely one of convention.An <em>abstract</em> method or propertyis one for which no implementation is given.<P>An abstract class is intended to be used as the<em>base class</em><A NAME=4361> </A>from which other classes are <em>derived</em><A NAME=4363> </A>.The derived classes are expected to <em>override</em><A NAME=4365> </A>the abstract methods and properties of the base classes.By defining abstract methods in the base class,it is possible to understand how an object of a derived class can be used.We don't need to know how a particular object instance is implemented,nor do we need to know of which derived class it is an instance.<P>This design pattern uses the idea of <em>polymorphism</em><A NAME=4367> </A>.Polymorphism literally means ``having many forms.''The essential idea is that a base classis used to define the set of values and the set of operations--the abstract data type.Then, various different implementations (<em>many forms</em>)of the abstract data type can be made.We do this by defining <em>abstract classes</em>that contain shared implementation featuresand then by deriving concrete classes from the abstract base classes.<P>The remainder of this section presents thetop levels of the class hierarchy shown in Figure <A HREF="page114.html#figclasses"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.The top levels define those attributes of objects whichare common to all of the classes in the hierarchy.The lower levels of the hierarchyare presented in subsequent chapters wherethe abstractions are defined andvarious implementations of those abstractions are elaborated.<P><HR><A NAME="tex2html2529" HREF="page115.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2527" HREF="page113.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2521" HREF="page113.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html2531" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <P><ADDRESS><img src="../icons/bruno.gif" alt="Bruno" align=right><a href="../copyright.html">Copyright © 2003</a> by <a href="../signature.html">Bruno R. Preiss, P.Eng.</a> All rights reserved.</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?