⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page604.html

📁 Data Structures And Algorithms With Object-Oriented Design Patterns In Python (2003) source code and
💻 HTML
字号:
<HTML><HEAD><TITLE>Abstract Methods</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="tex2html8094" HREF="page605.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html8092" HREF="page601.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html8086" HREF="page603.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html8096" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION0017623000000000000000">Abstract Methods</A></H3><P>The <tt>draw</tt> method defined in Program&nbsp;<A HREF="page602.html#proggraphicalObjecta"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>should never be called.This is because it is expected that every class derivedfrom the <tt>GraphicalObject</tt> class will override the <tt>draw</tt> method.Therefore,we define the <tt>draw</tt> method given in the <tt>GraphicalObject</tt> classto be an <tt>abstractmethod</tt>.<P>Unlike <tt>staticmethod</tt>,the <tt>abstractmethod</tt> class is not a built-in Python class.Program&nbsp;<A HREF="page117.html#progabstractmethoda"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> defines the <tt>abstractmethod</tt> class.<P>In order to understand what the <tt>abstractmethod</tt> class does,it is necessary to understand how the Python virtual machineinvokes instance methods.Consider the following method call:<PRE>g.draw()</PRE>The Python interpreter performs a sequence of operationsthat is equivalent to the following:<PRE>func = GraphicalObject.draw.__get__(g, GraphicalObject)func.__call__()</PRE>The purpose of the <tt>__get__</tt> method is to return a method objectthat is bound to an instance.The bound method object is then called like a normal functionby invoking the <tt>__call__</tt> method.<P>The <tt>__get__</tt> method of the <tt>abstractmethod</tt> classreturns an instance of the nested class called <tt>method</tt>.The <tt>__call__</tt> method of the nested <tt>method</tt> classraises a <tt>TypeError</tt> exception when called.<P><HR><A NAME="tex2html8094" HREF="page605.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html8092" HREF="page601.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html8086" HREF="page603.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html8096" 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -