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

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

?? sect14.htm

?? Pythn design pattern
?? 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一区二区三区免费野_久草精品视频
国产精品情趣视频| 亚洲自拍偷拍综合| 午夜精品成人在线视频| 91视频观看视频| 亚瑟在线精品视频| 久久综合色一综合色88| 91丨porny丨国产入口| 亚洲欧美日韩系列| 欧美在线不卡视频| 黄色精品一二区| 中文字幕一区二区三区不卡 | gogo大胆日本视频一区| 亚洲人午夜精品天堂一二香蕉| 51精品国自产在线| 成人va在线观看| 国产精品综合网| 日韩一区在线免费观看| 欧美色窝79yyyycom| 国产一区二区h| 视频精品一区二区| 中文字幕av在线一区二区三区| 欧美日韩成人在线一区| 91在线丨porny丨国产| 韩国av一区二区三区四区| 日韩av网站在线观看| 日韩中文字幕麻豆| 精品久久国产老人久久综合| 欧美日本韩国一区| 一本一本久久a久久精品综合麻豆 一本一道波多野结衣一区二区 | 色综合天天综合网国产成人综合天 | 精品国产乱码久久久久久闺蜜| 91国偷自产一区二区三区观看| 色婷婷综合中文久久一本| 欧美日韩精品一二三区| 亚洲va欧美va天堂v国产综合| 18涩涩午夜精品.www| 中文字幕一区二区三区色视频| 国产精品伦一区二区三级视频| 久久你懂得1024| 中文字幕中文字幕一区二区 | 99免费精品在线观看| 精品国产精品一区二区夜夜嗨| 亚洲免费观看高清| 亚洲在线视频免费观看| 亚洲免费资源在线播放| 亚洲色图欧美在线| 老司机精品视频线观看86| 久久国产麻豆精品| 91丝袜高跟美女视频| 8x福利精品第一导航| 国产视频一区二区三区在线观看| 国产精品伦理在线| 欧美aaaaa成人免费观看视频| 美女一区二区三区在线观看| www.激情成人| 精品1区2区3区| 欧美一区二区精品| 日韩欧美国产综合在线一区二区三区| 日韩一区二区视频| 亚洲一区免费视频| 国产传媒欧美日韩成人| 色狠狠综合天天综合综合| 日韩精品一区二区三区中文精品| 亚洲精选视频在线| 粉嫩av一区二区三区在线播放 | 国产精品二三区| 图片区小说区国产精品视频| 成人综合婷婷国产精品久久| 日韩视频一区在线观看| 亚洲一线二线三线久久久| 久久99九九99精品| 久久综合九色综合久久久精品综合| 亚洲一区在线免费观看| 色哟哟国产精品免费观看| 欧美国产日韩一二三区| 国产精品99久久久| 最新国产の精品合集bt伙计| 91国偷自产一区二区三区成为亚洲经典 | 国产精品天天摸av网| 国产精品888| 久久久.com| 成人黄色电影在线 | 亚洲靠逼com| 666欧美在线视频| 亚洲福利视频一区| 91精品国产入口| 国产伦精一区二区三区| 成人免费在线视频| 欧美日本在线一区| 寂寞少妇一区二区三区| 中文字幕在线不卡一区二区三区| 国产电影一区二区三区| 国产精品高潮呻吟久久| 成人av在线网站| 日韩不卡一二三区| 中文字幕五月欧美| 91精品国产综合久久久蜜臀粉嫩 | 日本aⅴ亚洲精品中文乱码| 精品国产电影一区二区| 色一区在线观看| 国产精品一区二区在线看| 午夜欧美大尺度福利影院在线看| 精品久久久久久久久久久久久久久 | 1024国产精品| 制服丝袜一区二区三区| 欧美日韩亚洲丝袜制服| 99国产精品久久久| 欧美一区二区播放| 国产日韩欧美在线一区| 欧美一区二区三区四区久久| 色呦呦日韩精品| k8久久久一区二区三区| 一区二区三区精品在线| 国产精品成人网| 亚洲色图视频网| 亚洲精品视频在线观看网站| 中文字幕日韩欧美一区二区三区| 久久久夜色精品亚洲| 久久综合狠狠综合| 国产日本一区二区| 中文一区在线播放| 欧美日韩在线播| 亚洲综合成人在线视频| 亚洲精品中文在线影院| 日韩高清欧美激情| 精品一区二区三区在线播放| 久久国产尿小便嘘嘘尿| 波多野洁衣一区| av网站免费线看精品| 欧美三级中文字幕| 欧美videossexotv100| 国产性做久久久久久| 亚洲欧美国产毛片在线| 秋霞av亚洲一区二区三| 国产精品综合av一区二区国产馆| 不卡av电影在线播放| 欧美精品九九99久久| 欧美精品一区二区三区四区 | 欧美日韩一区二区三区免费看| 在线综合+亚洲+欧美中文字幕| 久久久久一区二区三区四区| 悠悠色在线精品| 成人av综合在线| 精品va天堂亚洲国产| 亚洲男人天堂av| 懂色av一区二区在线播放| 日韩欧美中文字幕精品| 亚洲最新在线观看| 91麻豆精品秘密| 国产精品的网站| 国产成人无遮挡在线视频| 日韩欧美亚洲国产另类| 午夜成人免费视频| 91成人在线精品| 亚洲综合激情另类小说区| 91亚洲资源网| 一区二区三区四区视频精品免费 | 亚洲五月六月丁香激情| av电影在线不卡| 国产精品对白交换视频| 91在线porny国产在线看| 国产精品久久毛片a| 成人久久18免费网站麻豆| 亚洲色图视频网站| 在线亚洲欧美专区二区| 日韩精品一级中文字幕精品视频免费观看| 91亚洲男人天堂| 亚洲电影一区二区| 日韩一区二区三区av| 国产美女一区二区| 亚洲视频 欧洲视频| 欧美日韩午夜在线视频| 五月天亚洲精品| 2023国产精品| 色综合婷婷久久| 国产一区二区在线影院| 国产精品久久毛片av大全日韩| 欧美日韩一本到| 成人99免费视频| 久久激情五月婷婷| 亚洲久草在线视频| 久久久久久久久久久久电影| 色八戒一区二区三区| 国产精品18久久久久久vr| 亚洲成人免费看| 亚洲一区二区三区不卡国产欧美 | 精品成a人在线观看| 欧洲av一区二区嗯嗯嗯啊| 成人午夜私人影院| 久久精品国产澳门| 精品亚洲成a人| 午夜精品久久久久久不卡8050| 中日韩av电影| 国产精品嫩草影院av蜜臀| 久久久久久久综合狠狠综合| 91精品国产全国免费观看| 欧美色综合久久| 67194成人在线观看| 日韩欧美国产一二三区| 日韩欧美亚洲国产另类|