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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? sect14.htm

?? Pythn design pattern
?? HTM
?? 第 1 頁 / 共 5 頁
字號(hào):
<!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>.

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩中文字幕1| 日本不卡123| a4yy欧美一区二区三区| 欧美成va人片在线观看| 三级影片在线观看欧美日韩一区二区| 丁香啪啪综合成人亚洲小说| 久久久青草青青国产亚洲免观| 国产精品美女久久久久aⅴ| 国产精品国产三级国产三级人妇| 麻豆91小视频| 国产午夜亚洲精品不卡| 国产成人精品影视| 亚洲天堂久久久久久久| 91国内精品野花午夜精品| 亚洲午夜成aⅴ人片| 欧美日本在线播放| 国产精品一线二线三线| 中文字幕 久热精品 视频在线| 99久免费精品视频在线观看| 亚洲免费在线观看| 欧美一区日本一区韩国一区| 国产一区二区主播在线| 91亚洲国产成人精品一区二三| 国产精品国产三级国产普通话99 | 亚洲午夜视频在线观看| 91精品啪在线观看国产60岁| 日本sm残虐另类| www成人在线观看| 欧洲色大大久久| 成人涩涩免费视频| 天天射综合影视| 中文字幕五月欧美| 久久色.com| 日韩美一区二区三区| 91亚洲精华国产精华精华液| 国精产品一区一区三区mba桃花 | 精品视频123区在线观看| 免费在线观看一区| 一卡二卡欧美日韩| 国产欧美一区二区精品性色 | 国产精品视频一二三| 欧美日韩黄色一区二区| 欧美三级在线播放| 91成人免费网站| 在线观看免费成人| av成人动漫在线观看| 亚洲成人精品在线观看| 欧美va亚洲va国产综合| 一本色道久久加勒比精品| 国产jizzjizz一区二区| 国产精品一区二区三区四区| 国产精品亚洲人在线观看| 成人丝袜高跟foot| 日本精品一级二级| 91精品国产一区二区| 欧美一级搡bbbb搡bbbb| 91精选在线观看| 中文字幕欧美国产| 五月婷婷激情综合| 成人听书哪个软件好| 色婷婷久久综合| 久久久久亚洲蜜桃| 夜夜嗨av一区二区三区四季av| 午夜精品久久久| 福利一区福利二区| 欧美日韩久久一区二区| 欧美大片免费久久精品三p| 欧美一级生活片| 亚洲精选在线视频| 久久99热狠狠色一区二区| 91成人免费网站| 欧美亚洲图片小说| 日韩一区二区三区观看| 亚洲丝袜美腿综合| 五月天一区二区三区| av中文字幕不卡| 中文字幕欧美激情一区| 国产一区二区福利| 精品国产乱码久久久久久老虎| 日韩美女一区二区三区四区| 亚洲美女电影在线| 色哟哟欧美精品| 亚洲欧洲色图综合| 成人毛片视频在线观看| 久久精品日韩一区二区三区| 久久久久久久综合色一本| 免费观看在线色综合| 欧美日高清视频| 美女尤物国产一区| 久久久久久久久久久电影| 国产91综合网| 正在播放亚洲一区| 国产激情一区二区三区| 国产精品久久影院| 欧美三区在线观看| 麻豆精品蜜桃视频网站| 亚洲精品在线免费播放| 香蕉乱码成人久久天堂爱免费| 久久无码av三级| 亚洲日本青草视频在线怡红院| 亚洲午夜久久久久久久久电影网| 国产成人午夜高潮毛片| 国产精品成人在线观看| 欧美图区在线视频| 国产在线播放一区二区三区| 欧美tickling网站挠脚心| 日韩二区三区在线观看| 日韩女优av电影| 成人精品视频一区二区三区尤物| 一区二区三区免费| 久久综合给合久久狠狠狠97色69| 91麻豆国产福利在线观看| 久久激情综合网| 五月婷婷久久丁香| 亚洲人成在线观看一区二区| 色视频一区二区| 激情小说亚洲一区| 久久久久9999亚洲精品| 国产福利91精品| 久久国产精品72免费观看| 国产欧美日韩在线观看| 9l国产精品久久久久麻豆| 亚洲一区二区三区四区的| 国产欧美日韩精品a在线观看| 欧美日韩国产欧美日美国产精品| 国产一区视频在线看| 国产麻豆精品久久一二三| 一区二区三区不卡视频在线观看| 国产清纯在线一区二区www| 欧美喷潮久久久xxxxx| 欧美高清视频一二三区 | 成人va在线观看| 国产成人av一区二区三区在线观看| 日韩精品1区2区3区| 日韩电影在线一区| 国内精品伊人久久久久av影院| 日韩国产欧美在线观看| 久久aⅴ国产欧美74aaa| 石原莉奈一区二区三区在线观看| 久久精品视频在线免费观看 | 国产精品成人在线观看| 一区二区三区欧美| 国产欧美日韩视频在线观看| 欧美午夜在线观看| 欧美亚洲一区二区三区四区| 2021国产精品久久精品| 亚洲天天做日日做天天谢日日欢| 蜜桃视频第一区免费观看| 蜜臀av性久久久久蜜臀av麻豆 | 中文乱码免费一区二区| 亚洲欧美日韩国产成人精品影院| 午夜av电影一区| av一二三不卡影片| 精品国产制服丝袜高跟| 日本亚洲三级在线| 91在线视频免费91| 精品国产乱子伦一区| 三级一区在线视频先锋| av电影一区二区| 日韩网站在线看片你懂的| 视频一区二区三区入口| 色噜噜狠狠一区二区三区果冻| 2020国产精品久久精品美国| 性欧美疯狂xxxxbbbb| 欧美日韩在线观看一区二区| 亚洲一区二区中文在线| 成人激情校园春色| 国产精品人成在线观看免费| 国产激情一区二区三区桃花岛亚洲| 日本久久电影网| 91一区二区三区在线观看| 国产99久久精品| 色999日韩国产欧美一区二区| 欧美激情在线一区二区三区| 奇米色一区二区| 日韩欧美亚洲国产精品字幕久久久 | 国产精品萝li| 国产一区二区三区四区在线观看| 欧美最猛黑人xxxxx猛交| 亚洲乱码日产精品bd| 欧美日韩一级视频| 不卡视频一二三| 午夜精品福利视频网站| 欧美videossexotv100| 91麻豆视频网站| 秋霞电影一区二区| 国产精品丝袜黑色高跟| 91美女片黄在线| 日韩不卡免费视频| 亚洲视频中文字幕| 日韩精品一区二区三区中文不卡| 国内精品久久久久影院薰衣草 | 久久精品视频一区二区三区| av在线播放不卡| 日韩电影免费一区| 亚洲蜜臀av乱码久久精品蜜桃| 69久久99精品久久久久婷婷| 成人高清免费在线播放| 亚洲高清中文字幕| 一级精品视频在线观看宜春院|