亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? sect14.htm

?? this is the most basic to learn python
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<!--
This document was converted from RTF source: 
By rtftohtml 4.19
See http://www.sunpack.com/RTF
Filename:TIPython.rtf
Application Directory:c:\tools\rtf2html\
Subject:
Author:Bruce Eckel
Operator:Bruce Eckel
Document Comments:
Version Comments:
Comments:
Keywords:
Translation Date:12/31/2001
Translation Time:08:24:14
Translation Platform:Win32
Number of Output files:18
This File:Sect14.htm
SplitDepth=1
SkipNavPanel=1
SkipLeadingToc=1
SkipTrailingToc=1
GenContents=1
GenFrames=1
GenIndex=1
-->
<HEAD lang="en"><META http-equiv="Content-Type" content="text/html">
<TITLE>12: Pattern refactoring</TITLE>

<script language="JavaScript">
</script>
</head>


<BODY  BGCOLOR="#FFFFFF"><DIV ALIGN="CENTER">
  <a href="http://www.MindView.net">
  <img src="mindview.gif" alt="MindView Inc." BORDER = "0"></a>
  <CENTER>
    <FONT FACE="Verdana, Tahoma, Arial, Helvetica, Sans" size = "-1">
    <!-- [ <a href="README.txt">Viewing Hints</a> ]
    [ <a href="RevisionHistory.htm">Revision History</a> ] -->
    [ <a href="http://www.mindview.net/Books/TIPython/">Book Home Page</a> ]
    [ <a href="http://www.mindview.net/Etc/MailingList.html">Free Newsletter</a> ] <br>
    [ <a href="http://www.mindview.net/Seminars">Seminars</a> ]
    [ <a href="http://www.mindview.net/CDs">Seminars on CD ROM</a> ]
    [ <a href="http://www.mindview.net/Services">Consulting</a> ]
    </FONT>
  <H2><FONT FACE="Verdana, Tahoma, Arial, Helvetica, Sans">
  Thinking in Python<br>
  <small>Revision 0.1.2 (12/31/01) -- Incomplete and Unfinished</small></FONT></H2>
  <H3><FONT FACE="Verdana, Tahoma, Arial, Helvetica, Sans">
  by Bruce Eckel &copy;2002 MindView, Inc.</FONT></H3>
  
    <FONT FACE="Verdana, Tahoma, Arial, Helvetica, Sans" size = "-1">
     [ <a href="Sect13.htm">Previous Chapter</a> ] 
    
    [ <a href="javascript:window.location.href = 'Index.htm';">Table of Contents</a> ] 
  
        [ <a href="DocIdx.htm">Index</a> ]
        
     [ <a href="Sect15.htm">Next Chapter</a> ] 
    </FONT>
    
  </CENTER>
  </P></DIV><A NAME="_Toc476705918"></A><A NAME="_Toc534420131"></A><A NAME="Heading82"></A><FONT FACE = "Verdana, Tahoma, Arial, Helvetica, Sans"><H1 ALIGN="LEFT">
12: Pattern refactoring</H1></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia" SIZE=4 COLOR="Red">This chapter has not
had any significant translation yet.
</FONT><FONT FACE="Georgia" SIZE=4><A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_336">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">This chapter will look at the process of
solving a problem by applying design patterns in an evolutionary fashion. That
is, a first cut design will be used for the initial solution, and then this
solution will be examined and various design patterns will be applied to the
problem (some of which will work, and some of which won&#146;t). The key
question that will always be asked in seeking improved solutions is &#147;what
will change?&#148;
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_337">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">This process is similar to what Martin
Fowler talks about in his book <I>Refactoring: Improving the Design of Existing
Code</I></FONT><A NAME="fnB16" HREF="#fn16">[16]</A><FONT FACE="Georgia">
(although he tends to talk about pieces of code more than pattern-level
designs). You start with a solution, and then when you discover that it
doesn&#146;t continue to meet your needs, you fix it. Of course, this is a
natural tendency but in computer programming it&#146;s been extremely difficult
to accomplish with procedural programs, and the acceptance of the idea that we
<I>can</I> refactor code and designs adds to the body of proof that
object-oriented programming is &#147;a good thing.&#148;
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_338">Add Comment</A></FONT><A NAME="_Toc476705919"></A><A NAME="_Toc534420132"></A><BR></P></DIV>
<A NAME="Heading83"></A><FONT FACE = "Verdana, Tahoma, Arial, Helvetica, Sans"><H2 ALIGN="LEFT">
Simulating the trash recycler</H2></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The nature of this problem is that the
trash is thrown unclassified into a single bin, so the specific type information
is lost. But later, the specific type information must be recovered to properly
sort the trash. In the initial solution, RTTI (described in Chapter 12 of
<I>Thinking in Java, 2<SUP>nd</SUP> edition</I>) is used.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_339">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">This is not a trivial design because it
has an added constraint. That&#146;s what makes it interesting&#151;it&#146;s
more like the messy problems you&#146;re likely to encounter in your work. The
extra constraint is that the trash arrives at the trash recycling plant all
mixed together. The program must model the sorting of that trash. This is where
RTTI comes in: you have a bunch of anonymous pieces of trash, and the program
figures out exactly what type they are.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_340">Add Comment</A></FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE># c12:recyclea:RecycleA.py 
# Recycling with RTTI.

<font color=#0000ff>class</font> Trash:
  private double weight
  <font color=#0000ff>def</font> __init__(self, double wt): weight = wt 
  abstract double getValue()
  double getWeight(): <font color=#0000ff>return</font> weight 
  # Sums the value of Trash <font color=#0000ff>in</font> a bin:
  static void sumValue(Iterator it):
    double val = 0.0f
    <font color=#0000ff>while</font>(it.hasNext()):
      # One kind of RTTI:
      # A dynamically-checked cast
      Trash t = (Trash)it.next()
      # Polymorphism <font color=#0000ff>in</font> action:
      val += t.getWeight() * t.getValue()
      <font color=#0000ff>print</font> (
        <font color=#004488>"weight of "</font> +
        # Using RTTI to get type
        # information about the <font color=#0000ff>class</font>:
        t.getClass().getName() +
        <font color=#004488>" = "</font> + t.getWeight())

    <font color=#0000ff>print</font> <font color=#004488>"Total value = "</font> + val

<font color=#0000ff>class</font> Aluminum(Trash):
  static double val  = 1.67f
  <font color=#0000ff>def</font> __init__(self, double wt): .__init__(wt) 
  double getValue(): <font color=#0000ff>return</font> val 
  static void setValue(double newval):
    val = newval

<font color=#0000ff>class</font> Paper(Trash):
  static double val = 0.10f
  <font color=#0000ff>def</font> __init__(self, double wt): .__init__(wt) 
  double getValue(): <font color=#0000ff>return</font> val 
  static void setValue(double newval):
    val = newval

<font color=#0000ff>class</font> Glass(Trash):
  static double val = 0.23f
  <font color=#0000ff>def</font> __init__(self, double wt): .__init__(wt) 
  double getValue(): <font color=#0000ff>return</font> val 
  static void setValue(double newval):
    val = newval

<font color=#0000ff>class</font> RecycleA(UnitTest):
  Collection 
    bin = ArrayList(),
    glassBin = ArrayList(),
    paperBin = ArrayList(),
    alBin = ArrayList()
  <font color=#0000ff>def</font> __init__(self):
    # Fill up the Trash bin:
    <font color=#0000ff>for</font>(int i = 0 i &lt; 30 i++)
      switch((int)(Math.random() * 3)):
        case 0 :
          bin.add(new
            Aluminum(Math.random() * 100))
          <font color=#0000ff>break</font>
        case 1 :
          bin.add(new
            Paper(Math.random() * 100))
          <font color=#0000ff>break</font>
        case 2 :
          bin.add(new
            Glass(Math.random() * 100))

  <font color=#0000ff>def</font> test(self):
    Iterator sorter = bin.iterator()
    # Sort the Trash:
    <font color=#0000ff>while</font>(sorter.hasNext()):
      Object t = sorter.next()
      # RTTI to show <font color=#0000ff>class</font> membership:
      <font color=#0000ff>if</font>(t instanceof Aluminum)
        alBin.add(t)
      <font color=#0000ff>if</font>(t instanceof Paper)
        paperBin.add(t)
      <font color=#0000ff>if</font>(t instanceof Glass)
        glassBin.add(t)

    Trash.sumValue(alBin.iterator())
    Trash.sumValue(paperBin.iterator())
    Trash.sumValue(glassBin.iterator())
    Trash.sumValue(bin.iterator())

  <font color=#0000ff>def</font> main(self, String args[]):
    RecycleA().test()

# :~</PRE></FONT></BLOCKQUOTE><DIV ALIGN="LEFT"><P><A NAME="_Toc305593314"></A><A NAME="_Toc305628786"></A><FONT FACE="Georgia">In
the source code listings available for this book, this file will be placed in
the subdirectory <B>recyclea</B> that branches off from the subdirectory
<B>c12</B> (for Chapter 12). The unpacking tool takes care of placing it into
the correct subdirectory. The reason for doing this is that this chapter
rewrites this particular example a number of times and by putting each version
in its own directory (using the default package in each directory so that
invoking the program is easy), the class names will not clash.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_341">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Several
<A NAME="Index33"></A><B>ArrayList</B> objects are created to hold <B>Trash</B>
references. Of course, <B>ArrayList</B>s<B> </B>actually hold <B>Object</B>s so
they&#146;ll hold anything at all. The reason they hold <B>Trash </B>(or
something derived from <B>Trash</B>) is only because you&#146;ve been careful
to not put in anything except <B>Trash</B>. If you do put something
&#147;wrong&#148; into the <B>ArrayList</B>, you won&#146;t get any
compile-time warnings or errors&#151;you&#146;ll find out only via an
exception at run time.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_342">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">When the <B>Trash</B> references are
added, they lose their specific identities and become simply <B>Object
reference</B>s (they are <A NAME="Index34"></A><I>upcast</I>). However, because
of polymorphism <A NAME="Index35"></A>the proper behavior still occurs when the
dynamically-bound methods<A NAME="Index36"></A> are called through the
<A NAME="Index37"></A><B>Iterator</B> <B>sorter</B>, once the resulting
<A NAME="Index38"></A><B>Object</B> has been cast back to <B>Trash</B>.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产一区二区在线看| 日韩一区二区免费在线电影| 欧美色图激情小说| 欧美激情一区二区在线| 午夜精品久久久久久久99水蜜桃| 国产·精品毛片| 91麻豆精品国产91久久久使用方法 | 国产大陆精品国产| 欧美精品tushy高清| √…a在线天堂一区| 九九精品视频在线看| 欧美日韩一区二区在线观看视频| 国产精品国产三级国产普通话99| 久久精品国产成人一区二区三区 | 国产精品66部| 日韩欧美国产麻豆| 午夜精品一区二区三区免费视频| 99国产麻豆精品| 国产精品不卡在线| 国产精品一区二区久久不卡| 欧美电视剧免费全集观看| 午夜激情一区二区三区| 91啦中文在线观看| 欧美国产精品v| 国产精品一品视频| 2024国产精品| 精品一区二区三区久久久| 3751色影院一区二区三区| 亚洲国产精品久久久男人的天堂| 色综合久久久久久久久| 亚洲欧洲精品天堂一级| www..com久久爱| 国产精品传媒在线| 99久久夜色精品国产网站| 中文字幕一区二区三区蜜月 | 欧美专区日韩专区| 一区二区三区精品在线观看| 色婷婷精品久久二区二区蜜臂av | 麻豆91免费看| 久久综合九色综合97婷婷女人 | 麻豆成人91精品二区三区| 欧美岛国在线观看| 国产麻豆一精品一av一免费| 日本一区二区三区在线不卡| 顶级嫩模精品视频在线看| 中文字幕av一区二区三区| av电影在线观看不卡| 亚洲已满18点击进入久久| 精品视频1区2区| 麻豆精品一区二区| 国产午夜精品一区二区| 91在线观看美女| 视频在线观看91| 久久久久亚洲综合| 色成人在线视频| 日韩国产欧美在线观看| 久久精品人人爽人人爽| 91美女精品福利| 日韩高清不卡一区二区三区| 国产亚洲午夜高清国产拍精品| 波多野结衣精品在线| 午夜精品久久久久久久| 国产亚洲婷婷免费| 欧美午夜精品免费| 国产一区二区三区久久久| 成人免费在线视频观看| 日韩欧美视频一区| 99精品久久99久久久久| 蜜臀av性久久久久蜜臀aⅴ四虎| 国产精品美女久久久久av爽李琼| 欧美影院一区二区三区| 国产精品自拍在线| 亚洲国产va精品久久久不卡综合| 久久女同互慰一区二区三区| 欧洲另类一二三四区| 国产成人福利片| 日韩av一区二区三区| 国产精品久久久久久久裸模| 欧美一区二区日韩一区二区| 91在线视频播放| 激情五月婷婷综合| 性做久久久久久久免费看| 国产情人综合久久777777| 91麻豆精品91久久久久同性| 成人黄色一级视频| 久久91精品国产91久久小草| 亚洲综合久久av| 亚洲欧洲一区二区三区| 2欧美一区二区三区在线观看视频| 欧美午夜电影一区| 成人av电影免费观看| 国产精品夜夜嗨| 喷水一区二区三区| 亚洲高清免费视频| 亚洲男人天堂av网| 中文字幕电影一区| 精品国产免费一区二区三区香蕉| 精品视频一区 二区 三区| 色哟哟国产精品免费观看| 99这里只有久久精品视频| 国产电影一区二区三区| 国产一区二区美女诱惑| 久久国产福利国产秒拍| 轻轻草成人在线| 日本亚洲一区二区| 午夜精品在线视频一区| 天天影视涩香欲综合网| 亚洲一区二区三区影院| 一区二区三区四区在线播放| 亚洲视频免费在线观看| 中文字幕一区二区在线播放 | 欧美大片在线观看一区二区| 日韩三级精品电影久久久| 欧美精品少妇一区二区三区| 欧美一区二视频| 欧美一区二区三区日韩视频| 欧美日韩国产成人在线91| 欧美另类videos死尸| 91精品国产高清一区二区三区蜜臀| 在线电影院国产精品| 欧美va亚洲va| 国产午夜精品久久久久久免费视 | 日本美女一区二区三区视频| 日韩高清中文字幕一区| 免费看欧美女人艹b| 精品一区二区日韩| 成人在线视频一区| 色偷偷久久人人79超碰人人澡| 欧美亚洲综合在线| 6080国产精品一区二区| 欧美精品一区二区久久婷婷| 日本一区免费视频| 亚洲精品日韩一| 日本亚洲最大的色成网站www| 国内精品在线播放| 国产69精品一区二区亚洲孕妇| thepron国产精品| 欧美顶级少妇做爰| 久久先锋资源网| 夜夜嗨av一区二区三区四季av| 日韩av电影免费观看高清完整版 | 国产成人免费在线观看| 色婷婷久久综合| 日韩一区二区三区免费观看| 中文字幕不卡在线播放| 亚洲电影在线免费观看| 国产一区在线观看麻豆| 在线观看免费一区| 欧美电影免费观看完整版| 国产精品美女久久久久久久网站| 亚洲自拍偷拍图区| 国产成人超碰人人澡人人澡| 欧美日韩综合一区| 久久久久久综合| 午夜不卡av免费| 不卡av在线网| 日韩精品一区二区三区在线| 亚洲男女一区二区三区| 国产中文字幕精品| 欧美另类一区二区三区| 自拍偷拍亚洲综合| 国产在线视视频有精品| 在线成人高清不卡| 一区二区三区中文字幕精品精品| 国产一区二区在线免费观看| 欧美男女性生活在线直播观看| 国产视频一区二区在线观看| 日韩av在线发布| 色哟哟精品一区| 国产欧美综合色| 美女精品自拍一二三四| 精品视频一区 二区 三区| 国产精品理伦片| 国产一区欧美二区| 日韩色在线观看| 视频一区二区不卡| 欧美私人免费视频| 亚洲色大成网站www久久九九| 国内精品国产三级国产a久久| 欧美日韩国产三级| 一区二区三区波多野结衣在线观看| 国产精品99久久久久久久女警 | 国产一区二区三区最好精华液| 欧美一区二区三区思思人| 亚洲一区二区精品视频| 波多野洁衣一区| 国产精品久久久久久久久果冻传媒| 国内外精品视频| 精品久久久久一区二区国产| 日韩av二区在线播放| 在线播放欧美女士性生活| 性做久久久久久| 欧美视频你懂的| 亚洲成人动漫在线免费观看| 欧美日韩在线亚洲一区蜜芽| 亚洲第一二三四区| 欧美日韩高清一区二区三区| 视频一区二区三区入口| 日韩欧美综合一区| 国内精品国产成人国产三级粉色|