📄 104.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Robots" content="INDEX,NOFOLLOW">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<TITLE>Safari | Python Developer's Handbook -> Object-Oriented Programming</TITLE>
<LINK REL="stylesheet" HREF="oreillyi/oreillyN.css">
</HEAD>
<BODY bgcolor="white" text="black" link="#990000" vlink="#990000" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" cellpadding=5 cellspacing=0 border=0 class="navtopbg"><tr><td><font size="1"><p class="navtitle"><a href="8.html" class="navtitle">Web Development</a> > <a href="0672319942.html" class="navtitle">Python Developer's Handbook</a> > <a href="102.html" class="navtitle">5. Object-Oriented Programming</a> > <span class="nonavtitle">Object-Oriented Programming</span></p></font></td><td align="right" valign="top" nowrap><font size="1"><a href="main.asp?list" class="safnavoff">See All Titles</a></font></td></tr></table>
<TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="103.html" title="5. Object-Oriented Programming"><font size="1">< BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0672319942&snode=104" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="104.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="105.html" title="An Introduction to Python OOP"><font size="1">CONTINUE ></font></a></td></TR></TABLE>
<a href="5%2F31%2F2002+4%3A33%3A02+PM.html" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><font color=white size=1>152015024128143245168232148039199167010047123209178152124239215162147039203228125244193003</font><a href="read1.asp?bookname=0672319942&snode=104&now=5%2F31%2F2002+4%3A33%3A02+PM" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><br>
<FONT><h3>Object-Oriented Programming</h3>
<p>Python uses the traditional class architecture for object-oriented programming (OOP).</p>
<P>The object-oriented model adopted by Python</P>
<UL>
<li><p>Promotes modular design</p>
</LI>
<LI><p>Promotes and facilitates Python software reusability</p>
</li>
<LI><P>Uses notions of real-world objects to develop programs</P>
</li>
<li><p>Results in better quality software (but, of course, you can write bad code with any paradigm)</p>
</li>
</ul>
<p>Object-oriented programming promotes data abstraction, information hiding, encapsulation, and modular programming.</p>
<p>Saying that OOP promotes data abstraction means that we define the functions that operate on the data. The ideal scenario provides encapsulated data that can be accessible only through the class methods. However, in Python, we cannot totally block the programmer from accessing the information that is stored inside a class.</p>
<p>Encapsulation, Inheritance, and Polymorphism are the most important thoughts provided by OOP. Python doesn't strictly follow the standard concepts, but you will see how far it goes.<a name="idx1073743247"></A><a nAme="idx1073743248"></a></P>
<blocKquoTE>
<P><P><b>Encapsulation棤</b>
Data can only be accessed or manipulated by means of a set of interface functions. Encapsulation of data enables information hiding. Python provides encapsulation through conventions rather than strictly enforcing it, which can be preferable.</p>
</p>
<P><P><B>Inheritance棤</B>
With inheritance, the derived class (also known as subclass, descendant, or child class) inherits the data members and class methods of its base (parent) class.</p>
</p>
<p><p><B>Polymorphism棤</B>
It enables a function to have several different kinds of interfaces. Depending on the parameters used by the caller, the class knows which interface should be used. Python achieves this through its dynamic typing and late binding.</P>
</P>
</blocKQUOte>
</font>
<P><TABLE width="100%" border=0><TR valign="top"><TD><font size=1 color="#C0C0C0"><br></font></TD><TD align=right><font size=1 color="#C0C0C0">Last updated on 1/30/2002<br>Python Developer's Handbook, © 2002 Sams Publishing</font></TD></TR></TABLE></P>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="103.html" title="5. Object-Oriented Programming"><font size="1">< BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0672319942&snode=104" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="104.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="105.html" title="An Introduction to Python OOP"><font size="1">CONTINUE ></font></a></td></TR></TABLE>
</TD></TR></TABLE>
<br><TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD><H4 class=Title>Index terms contained in this section</H4>
<font size=2>
<a href="#idx1073743247">object-oriented programming (OOP)</a><BR>
programming<BR>
<a href="#idx1073743248">object-oriented (OOP)</a><BR>
<BR>
</font></TD></TR></TABLE>
<!--EndOfBrowse-->
</TD></TR></TABLE>
<table width=100% border=0 cellspacing=0 cellpadding=0 bgcolor=#990000><tr><td><p align=center><font size=1 face="verdana,arial,helvetica" color=white>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -