page605.html

来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 50 行

HTML
50
字号
<HTML><HEAD><TITLE>Algorithmic Abstraction</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="tex2html8103" HREF="page606.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html8101" HREF="page601.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html8097" HREF="page604.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html8105" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION0017624000000000000000">Algorithmic Abstraction</A></H3><P>An <em>abstract class</em><A NAME=57406>&#160;</A><A NAME=57407>&#160;</A>is a class that contains one or more abstract methods.Abstract classes can be used in many interesting ways.One of the most useful paradigms is the use of an abstract classfor <em>algorithmic abstraction</em><A NAME=57409>&#160;</A>.The <tt>erase</tt> and <tt>moveTo</tt> methodsdefined in Program&nbsp;<A HREF="page602.html#proggraphicalObjecta"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>are examples of this.<P>The <tt>erase</tt> and <tt>moveTo</tt> methods are implemented inthe abstract class <tt>GraphicalObject</tt>.The algorithms implemented are designed to work in anyconcrete class derived from <tt>GraphicalObject</tt>,be it <tt>Circle</tt>, <tt>Rectangle</tt> or <tt>Square</tt>.In effect, we have written algorithms that workregardless of the actual class of the object.Therefore, such algorithms are called <em>abstract algorithms</em>.<P>Abstract algorithms typically invoke abstract methods.For example, both <tt>moveTo</tt> and <tt>erase</tt>ultimately invoke <tt>draw</tt>to do most of the actual work.In this case,the derived classes are expected to inheritthe abstract algorithms <tt>moveTo</tt> and <tt>erase</tt>and to override the abstract method <tt>draw</tt>.Thus, the derived class customizes the behavior of the abstract algorithmby overriding the appropriate methods.The Python method resolution mechanism ensures thatthe ``correct'' method is always called.<P><HR><A NAME="tex2html8103" HREF="page606.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html8101" HREF="page601.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html8097" HREF="page604.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html8105" 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 &#169; 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 + -
显示快捷键?