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

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

?? sect14.htm

?? Pythn design pattern
?? HTM
?? 第 1 頁 / 共 5 頁
字號:

<BLOCKQUOTE><FONT SIZE = "+1"><PRE># c12:trash:Trash.dat
c12.trash.Glass:54
c12.trash.Paper:22
c12.trash.Paper:11
c12.trash.Glass:17
c12.trash.Aluminum:89
c12.trash.Paper:88
c12.trash.Aluminum:76
c12.trash.Cardboard:96
c12.trash.Aluminum:25
c12.trash.Aluminum:34
c12.trash.Glass:11
c12.trash.Glass:68
c12.trash.Glass:43
c12.trash.Aluminum:27
c12.trash.Cardboard:44
c12.trash.Aluminum:18
c12.trash.Paper:91
c12.trash.Glass:63
c12.trash.Glass:50
c12.trash.Glass:80
c12.trash.Aluminum:81
c12.trash.Cardboard:12
c12.trash.Glass:12
c12.trash.Glass:54
c12.trash.Aluminum:36
c12.trash.Aluminum:93
c12.trash.Glass:93
c12.trash.Paper:80
c12.trash.Glass:36
c12.trash.Glass:12
c12.trash.Glass:60
c12.trash.Paper:66
c12.trash.Aluminum:36
c12.trash.Cardboard:22
# :~</PRE></FONT></BLOCKQUOTE><DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Note that the class path must
be included when giving the class names, otherwise the class will not be found.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_377">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">This file is read using the
previously-defined <B>StringList </B>tool, and each line is picked aparat using
</FONT><FONT FACE="Georgia"> the <A NAME="Index68"></A><B>String </B>method
<A NAME="Index69"></A><B>indexOf(&#160;)</B> to produce the index of the
&#145;<B>:</B>&#146;. This is first used with the <B>String </B>method
<A NAME="Index70"></A><A NAME="Index71"></A><B>substring(&#160;) </B>to extract
the name of the trash type, and next to get the weight that is turned into a
<B>double </B>with the <B>static <A NAME="Index72"></A>Double.valueOf(&#160;)
</B>method. The <A NAME="Index73"></A><A NAME="Index74"></A><B>trim(&#160;)</B>
method removes white space at both ends of a string.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_378">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The <B>Trash </B>parser is placed in a
separate file since it will be reused throughout this chapter:
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_379">Add Comment</A></FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE># c12:trash:ParseTrash.py 
# Parse file contents into Trash objects,
# placing each into a Fillable holder.

<font color=#0000ff>class</font> ParseTrash:
  <font color=#0000ff>def</font> fillBin(String filename, Fillable bin):
    <font color=#0000ff>for</font> line <font color=#0000ff>in</font> open(filename).readlines():
      String type = line.substring(0, 
        line.index(':')).strip()
      double weight = Double.valueOf(
        line.substring(line.index(':') + 1)
          .strip()).doubleValue()
      bin.addTrash(
        Trash.factory(
          Trash.Messenger(type, weight)))

  # Special case to handle Collection:
  <font color=#0000ff>def</font> fillBin(String filename, Collection bin):
    fillBin(filename, FillableCollection(bin))

# :~</PRE></FONT></BLOCKQUOTE><DIV ALIGN="LEFT"><P><FONT FACE="Georgia">In <B>RecycleA.py</B>, an
<B>ArrayList</B> was used to hold the <B>Trash</B> objects. However, other types
of containers can be used as well. To allow for this, the first version of
<B>fillBin(&#160;)</B> takes a reference to a <B>Fillable</B>, which is simply
an <B>interface</B> that supports a method called <B>addTrash(&#160;)</B>:
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_380">Add Comment</A></FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE># c12:trash:Fillable.py 
# Any object that can be filled with Trash.

<font color=#0000ff>class</font> Fillable:
  <font color=#0000ff>def</font> addTrash(self, Trash t)
# :~</PRE></FONT></BLOCKQUOTE><DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Anything that supports this
interface can be used with <B>fillBin</B>. Of course, <B>Collection</B>
doesn&#146;t implement <B>Fillable</B>, so it won&#146;t work. Since
<B>Collection</B> is used in most of the examples, it makes sense to add a
second overloaded <B>fillBin(&#160;)</B> method that takes a <B>Collection</B>.
Any <B>Collection</B> can then be used as a <B>Fillable</B> object using an
adapter class:
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_381">Add Comment</A></FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE># c12:trash:FillableCollection.py 
# Adapter that makes a Collection Fillable.

<font color=#0000ff>class</font> FillableCollection(Fillable):
  private Collection c
  <font color=#0000ff>def</font> __init__(self, Collection cc): 
    c = cc 

  <font color=#0000ff>def</font> addTrash(self, Trash t):
    c.add(t)

# :~</PRE></FONT></BLOCKQUOTE><DIV ALIGN="LEFT"><P><FONT FACE="Georgia">You can see that the only job
of this class is to connect <B>Fillable</B>&#146;s <B>addTrash(&#160;)</B>
method to <B>Collection&#146;s</B> <B>add(&#160;)</B>. With this class in hand,
the overloaded <B>fillBin(&#160;)</B> method can be used with a
<B>Collection</B> in <B>ParseTrash.py</B>:
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_382">Add Comment</A></FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE>  public static void 
  fillBin(String filename, Collection bin):
    fillBin(filename, FillableCollection(bin))
</PRE></FONT></BLOCKQUOTE><DIV ALIGN="LEFT"><P><FONT FACE="Georgia">This approach works for any
container class that&#146;s used frequently. Alternatively, the container class
can provide its own adapter that implements <B>Fillable</B>. (You&#146;ll see
this later, in <B>DynaTrash.py</B>.)
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_383">Add Comment</A></FONT><A NAME="_Toc534420138"></A><BR></P></DIV>
<A NAME="Heading89"></A><FONT FACE = "Verdana, Tahoma, Arial, Helvetica, Sans"><H3 ALIGN="LEFT">
Recycling with prototyping</H3></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Now you can see the revised version of
<B>RecycleA.py</B> using the
<A NAME="Index75"></A><A NAME="Index76"></A>prototyping technique:
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_384">Add Comment</A></FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE># c12:recycleap:RecycleAP.py 
# Recycling with RTTI <font color=#0000ff>and</font> Prototypes.

<font color=#0000ff>class</font> RecycleAP(UnitTest):
  Collection
    bin = ArrayList(), 
    glassBin = ArrayList(),
    paperBin = ArrayList(),
    alBin = ArrayList()
  <font color=#0000ff>def</font> __init__(self):
    # Fill up the Trash bin:
    ParseTrash.fillBin(
      <font color=#004488>"..</font><font color=#004488>/trash</font><font color=#004488>/Trash.dat"</font>, bin)

  <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[]):
    RecycleAP().test()

# :~</PRE></FONT></BLOCKQUOTE><DIV ALIGN="LEFT"><P><FONT FACE="Georgia">All of the <B>Trash</B>
objects, as well as the <B>ParseTrash</B> and support classes, are now part of
the package <B>c12.trash</B>, so they are simply imported.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_385">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The process of opening the data file
containing <B>Trash</B> descriptions and the parsing of that file have been
wrapped into the <B>static</B> method <B>ParseTrash.fillBin(&#160;)</B>, so now
it&#146;s no longer a part of our design focus. You will see that throughout
the rest of the chapter, no matter what new classes are added,
<B>ParseTrash.fillBin(&#160;)</B> will continue to work without change, which
indicates a good design.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_386">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">In terms of object creation, this design
does indeed severely localize the changes you need to make to add a new type to
the system. However, there&#146;s a significant problem in the use of RTTI that
shows up clearly here. The program seems to run fine, and yet it never detects
any cardboard, even though there is cardboard in the list! This happens
<I>because</I> of the use of RTTI, which looks for only the types that you tell
it to look for. The clue that <A NAME="Index77"></A>RTTI is being misused is
that <I>every type in the system </I>is being tested, rather than a single type
or subset of types. As you will see later, there are ways to use polymorphism
instead when you&#146;re testing for every type. But if you use RTTI a lot in
this fashion, and you add a new type to your system, you can easily forget to
make the necessary changes in your program and produce a difficult-to-find bug.
So it&#146;s worth trying to eliminate RTTI in this case, not just for
aesthetic reasons&#151;it produces more maintainable code.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_387">Add Comment</A></FONT><A NAME="_Toc375545416"></A><A NAME="_Toc476705923"></A><A NAME="_Toc534420139"></A><BR></P></DIV>
<A NAME="Heading90"></A><FONT FACE = "Verdana, Tahoma, Arial, Helvetica, Sans"><H2 ALIGN="LEFT">
Abstracting usage</H2></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">With creation out of the way, it&#146;s
time to tackle the remainder of the design: where the classes are used. Since
it&#146;s the act of sorting into bins that&#146;s particularly ugly and
exposed, why not take that process and hide it inside a class? This is the
principle of &#147;If you must do something ugly, at least localize the
ugliness inside a class.&#148; It looks like this:
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_388">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="CENTER"><FONT FACE="Georgia"><IMG SRC="TIPyth06.gif"></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The <B>TrashSorter</B> object
initialization must now be changed whenever a new type of <B>Trash</B> is added
to the model. You could imagine that the <B>TrashSorter</B> class might look
something like this:
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_389">Add Comment</A></FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE><font color=#0000ff>class</font> TrashSorter(ArrayList):
  <font color=#0000ff>def</font> sort(self, Trash t): <font color=#009900>/* ... */</font> 
</PRE></FONT></BLOCKQUOTE><DIV ALIGN="LEFT"><P><FONT FACE="Georgia">That is, <B>TrashSorter</B> is an
<B>ArrayList</B> of references to <B>ArrayList</B>s of <B>Trash</B> references,
and with <B>add(&#160;)</B> you can install another one, like so:
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_390">Add Comment</A></FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE>TrashSorter ts = TrashSorter()
ts.add(ArrayList())</PRE></FONT></BLOCKQUOTE><DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Now, however,
<B>sort(&#160;)</B> becomes a problem. How does the statically-coded method deal
with the fact that a new type has been added? To solve this, the type
information must be removed from <B>sort(&#160;)</B> so that all it needs to do
is call a generic method that takes care of the details of type. This, of
course, is another way to describe a dynamically-bound method. So
<B>sort(&#160;)</B> will simply move through the sequence and call a
dynamically-bound method for each <B>ArrayList</B>. Since the job of this method
is to grab the pieces of trash it is interested in, it&#146;s called

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲韩国精品一区| 国产一区二区三区视频在线播放| 亚洲视频一区二区在线观看| 偷拍日韩校园综合在线| av在线不卡电影| 精品福利二区三区| 视频一区欧美精品| 日本二三区不卡| 久久婷婷国产综合精品青草| 综合亚洲深深色噜噜狠狠网站| 99久久婷婷国产| 中文字幕第一区| 国产一区二区视频在线| 中文字幕av资源一区| 91欧美激情一区二区三区成人| 国产亚洲美州欧州综合国| 日本亚洲电影天堂| 在线播放中文一区| 亚洲成人av福利| 欧美中文字幕一二三区视频| 国产精品蜜臀在线观看| 久久er99热精品一区二区| 7777精品伊人久久久大香线蕉| 亚洲丝袜自拍清纯另类| 欧美日韩二区三区| 日韩成人精品在线| 国产亚洲欧美色| 欧美网站一区二区| 亚洲一级电影视频| 欧美日韩国产欧美日美国产精品| 激情av综合网| 精品久久国产老人久久综合| 麻豆精品新av中文字幕| 精品少妇一区二区三区| 99久久精品免费| 国内欧美视频一区二区| 亚洲电影中文字幕在线观看| 久久免费美女视频| 成人永久看片免费视频天堂| 国产亚洲成aⅴ人片在线观看| 一本色道**综合亚洲精品蜜桃冫| 一区二区三区在线影院| 欧美手机在线视频| 国产乱人伦偷精品视频不卡| 精品国产免费人成电影在线观看四季 | 99热在这里有精品免费| 日本不卡不码高清免费观看| 日韩一级精品视频在线观看| 蜜桃av一区二区| 亚洲精品久久嫩草网站秘色| 欧美综合视频在线观看| 国产成人亚洲精品青草天美| 国产欧美日韩精品a在线观看| 国产白丝网站精品污在线入口| 国产精品久久99| 欧美日韩视频第一区| 韩国在线一区二区| 婷婷一区二区三区| 亚洲自拍偷拍九九九| 亚洲欧洲一区二区在线播放| 欧美日韩精品高清| 一本高清dvd不卡在线观看| 成人美女视频在线观看18| 蜜乳av一区二区| 午夜伊人狠狠久久| 亚洲成人动漫精品| 亚洲超碰97人人做人人爱| 亚洲精品视频在线观看网站| 日韩码欧中文字| 亚洲欧美日韩久久| 日韩免费看的电影| 99久久精品免费精品国产| 国产精品亚洲一区二区三区妖精| 免费观看在线综合| 麻豆精品久久久| 麻豆国产一区二区| 韩国女主播一区| 黄网站免费久久| 国产一区高清在线| 久久er99热精品一区二区| 毛片av一区二区| 蜜桃av噜噜一区二区三区小说| 日韩av电影天堂| 日本v片在线高清不卡在线观看| 日韩国产精品久久久久久亚洲| 亚洲成人资源在线| 日韩成人精品在线| 精品一区中文字幕| 亚洲国产毛片aaaaa无费看| 亚洲一区二区不卡免费| 亚洲18影院在线观看| 午夜精品123| 久久电影网站中文字幕| 国内成人免费视频| 91原创在线视频| 欧美三级在线播放| 日韩欧美国产1| 国产欧美一区在线| 一区二区欧美精品| 日韩av二区在线播放| 国产精品18久久久久久久久久久久| 国产伦精品一区二区三区免费迷| 成人午夜在线播放| 欧美三级日韩在线| 精品久久国产老人久久综合| 欧美高清在线一区二区| 亚洲综合一区二区三区| 美腿丝袜亚洲三区| 成人精品视频一区| 欧美欧美午夜aⅴ在线观看| 2022国产精品视频| 亚洲精品一卡二卡| 九九精品一区二区| 色8久久精品久久久久久蜜| 日韩免费成人网| 亚洲另类色综合网站| 免费av网站大全久久| av中文字幕在线不卡| 91麻豆精品国产自产在线观看一区 | 国产亚洲欧美一级| 亚洲影院久久精品| 国产精品一区二区视频| 在线亚洲人成电影网站色www| 日韩欧美一二区| 亚洲日韩欧美一区二区在线| 免费的国产精品| 色综合久久88色综合天天免费| 欧美一级高清片在线观看| 自拍偷拍亚洲激情| 国产精品亚洲第一区在线暖暖韩国 | 国产欧美日韩精品在线| 日产国产高清一区二区三区| 国产白丝网站精品污在线入口| 欧美精选午夜久久久乱码6080| 国产精品色一区二区三区| 香蕉久久夜色精品国产使用方法| 国产suv精品一区二区883| 91麻豆精品久久久久蜜臀| 曰韩精品一区二区| 成人一区二区三区视频在线观看| 91精品欧美综合在线观看最新| 亚洲女同一区二区| 成人中文字幕在线| 精品国产麻豆免费人成网站| 亚洲国产综合在线| 91色视频在线| 中文字幕一区av| 国产成人精品免费| 久久一二三国产| 久久99精品国产麻豆婷婷| 欧美日韩一区二区三区视频| 日韩一区在线播放| 激情文学综合插| 欧美日韩国产大片| 亚洲成人动漫精品| 欧美性xxxxxxxx| 一区二区三区波多野结衣在线观看 | 老司机精品视频导航| 欧美精品在线观看一区二区| 1区2区3区精品视频| 国产精品亚洲а∨天堂免在线| 精品日产卡一卡二卡麻豆| 日本成人在线电影网| 欧美电影一区二区| 日韩精品乱码av一区二区| 欧美美女直播网站| 日韩精品电影一区亚洲| 91精品国产色综合久久| 国产午夜亚洲精品不卡| 精品一区二区在线视频| 日韩精品一区二区三区在线播放 | 亚洲男人天堂一区| 一本久久综合亚洲鲁鲁五月天| 亚洲欧美日韩一区| 欧美日韩国产免费一区二区 | 亚洲bt欧美bt精品| 欧美精品乱码久久久久久按摩 | 国产自产视频一区二区三区| 精品国产区一区| 国产在线播放一区| 欧美极品另类videosde| 成人深夜视频在线观看| 中文字幕五月欧美| 在线免费观看日本一区| 亚洲国产成人高清精品| 欧美一级黄色大片| 国产91色综合久久免费分享| 亚洲色图制服丝袜| 欧美精品久久天天躁| 国产在线一区二区| 国产日产欧美一区二区三区| 99国产精品久久| 图片区小说区国产精品视频| 欧美成人在线直播| 粉嫩久久99精品久久久久久夜| 成人免费在线播放视频| 欧美精品久久久久久久多人混战| 老鸭窝一区二区久久精品| 国产精品电影一区二区| 欧美日韩亚洲国产综合|