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

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

?? sect14.htm

?? Pythn design pattern
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
<B>grab(Trash)</B>. The structure now looks like:
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_391">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="CENTER"><FONT FACE="Georgia"><IMG SRC="TIPyth07.gif"></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia"><B>TrashSorter</B> needs to call each
<B>grab(&#160;)</B> method and get a different result depending on what type of
<B>Trash</B> the current <B>ArrayList</B> is holding. That is, each
<B>ArrayList</B> must be aware of the type it holds. The classic approach to
this problem is to create a base &#147;<B>Trash</B> bin&#148; class and
inherit a new derived class for each different type you want to hold. If Java
had a parameterized type mechanism that would probably be the most
straightforward approach. But rather than hand-coding all the classes that such
a mechanism should be building for us, further observation can produce a better
approach.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_392">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">A basic OOP design principle is
&#147;Use data members for variation in state, use
<A NAME="Index78"></A>polymorphism for variation in behavior.&#148; Your first
thought might be that the <B>grab(&#160;)</B> method certainly behaves
differently for an <B>ArrayList</B> that holds <B>Paper</B> than for one that
holds <B>Glass</B>. But what it does is strictly dependent on the type, and
nothing else. This could be interpreted as a different state, and since Java has
a class to represent type (<B>Class</B>) this can be used to determine the type
of <B>Trash</B> a particular <B>Tbin</B> will hold.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_393">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The constructor for this <B>Tbin
</B>requires that you hand it the <B>Class</B> of your choice. This tells the
<B>ArrayList</B> what type it is supposed to hold. Then the <B>grab(&#160;)</B>
method uses <B>Class BinType</B> and RTTI to see if the <B>Trash</B> object
you&#146;ve handed it matches the type it&#146;s supposed to grab.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_394">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Here is the new version of the
program:</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE># c12:recycleb:RecycleB.py
# Containers that grab objects of interest.

# A container that admits only the right type
# of Trash (established <font color=#0000ff>in</font> the constructor):
<font color=#0000ff>class</font> Tbin:
  private Collection list = ArrayList()
  private Class type
  <font color=#0000ff>def</font> __init__(self, Class binType): type = binType 
  <font color=#0000ff>def</font> grab(self, Trash t):
    # Comparing <font color=#0000ff>class</font> types:
    <font color=#0000ff>if</font>(t.getClass().equals(type)):
      list.add(t)
      <font color=#0000ff>return</font> 1 # Object grabbed

    <font color=#0000ff>return</font> 0 # Object <font color=#0000ff>not</font> grabbed

  <font color=#0000ff>def</font> iterator(self):
    <font color=#0000ff>return</font> list.iterator()

<font color=#0000ff>class</font> TbinList(ArrayList):
  <font color=#0000ff>def</font> sort(self, Trash t):
    Iterator e = iterator() # Iterate over self
    <font color=#0000ff>while</font>(e.hasNext())
      <font color=#0000ff>if</font>(((Tbin)e.next()).grab(t)) <font color=#0000ff>return</font>
    # Need a Tbin <font color=#0000ff>for</font> this type:
    add(Tbin(t.getClass()))
    sort(t) # Recursive call

<font color=#0000ff>class</font> RecycleB(UnitTest):
  Collection bin = ArrayList()
  TbinList trashBins = TbinList()
  <font color=#0000ff>def</font> __init__(self):
    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 it = bin.iterator()
    <font color=#0000ff>while</font>(it.hasNext())
      trashBins.sort((Trash)it.next())
    Iterator e = trashBins.iterator()
    <font color=#0000ff>while</font>(e.hasNext()):
      Tbin b = (Tbin)e.next()
      Trash.sumValue(b.iterator())

    Trash.sumValue(bin.iterator())

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

# :~</PRE></FONT></BLOCKQUOTE><DIV ALIGN="LEFT"><P><FONT FACE="Georgia"><B>Tbin</B> contains a
<B>Class</B> reference <B>type</B> which establishes in the constructor what
what type it should grab. The <B>grab()</B> method checks this type against the
object you pass it. Note that in this design, <B>grab()</B> only accepts
<B>Trash</B> objects so you get compile-time type checking on the base type, but
you could also just accept <B>Object</B> and it would still work.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_395">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia"><B>T</B></FONT><FONT FACE="Georgia"><B>binList</B>
holds a set of <B>Tbin</B> references, so that <B>sort(&#160;)</B> can iterate
through the <B>Tbin</B>s when it&#146;s looking for a match for the
<B>Trash</B> object you&#146;ve handed it. If it doesn&#146;t find a match, it
creates a new <B>Tbin</B> for the type that hasn&#146;t been found, and makes a
recursive call to itself &#150; the next time around, the new bin will be
found.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_396">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Notice the genericity of this code: it
doesn&#146;t change at all if new types are added. If the bulk of your code
doesn&#146;t need changing when a new type is added (or some other change
occurs) then you have an easily extensible
system.</FONT><FONT FACE="Georgia"><A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_397">Add Comment</A></FONT><A NAME="_Toc375545417"></A><A NAME="_Toc476705924"></A><A NAME="_Toc534420140"></A><BR></P></DIV>
<A NAME="Heading91"></A><FONT FACE = "Verdana, Tahoma, Arial, Helvetica, Sans"><H2 ALIGN="LEFT">
Multiple dispatching</H2></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The above design is certainly
satisfactory. Adding new types to the system consists of adding or modifying
distinct classes without causing code changes to be propagated throughout the
system. In addition, RTTI is not &#147;misused&#148; as it was in
<B>RecycleA.py</B>. However, it&#146;s possible to go one step further and take
a purist viewpoint about <A NAME="Index79"></A>RTTI and say that it should be
eliminated altogether from the operation of sorting the trash into bins.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_398">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">To accomplish this, you must first take
the perspective that all type-dependent activities&#151;such as detecting the
type of a piece of trash and putting it into the appropriate bin&#151;should be
controlled through polymorphism and dynamic binding.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_399">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The previous examples first sorted by
type, then acted on sequences of elements that were all of a particular type.
But whenever you find yourself picking out particular types, stop and think. The
whole idea of polymorphism (dynamically-bound method calls) is to handle
type-specific information for you. So why are you hunting for types?
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_400">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The answer is something you probably
don&#146;t think about: Python performs only single dispatching. That is, if
you are performing an operation on more than one object whose type is unknown,
Python will invoke the dynamic binding mechanism on only one of those types.
This doesn&#146;t solve the problem, so you end up detecting some types
manually and effectively producing your own dynamic binding behavior.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_401">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The solution is called
<A NAME="Index80"></A><A NAME="Index81"></A><I>multiple dispatching</I>, which
means setting up a configuration such that a single method call produces more
than one dynamic method call and thus determines more than one type in the
process. To get this effect, you need to work with more than one type hierarchy:
you&#146;ll need a type hierarchy for each dispatch. The following example
works with two hierarchies: the existing <B>Trash</B> family and a hierarchy of
the types of trash bins that the trash will be placed into. This second
hierarchy isn&#146;t always obvious and in this case it needed to be created in
order to produce multiple dispatching (in this case there will be only two
dispatches, which is referred to as
<A NAME="Index82"></A><A NAME="Index83"></A><I>double dispatching</I>).
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_402">Add Comment</A></FONT><A NAME="_Toc476705925"></A><A NAME="_Toc534420141"></A><BR></P></DIV>
<A NAME="Heading92"></A><FONT FACE = "Verdana, Tahoma, Arial, Helvetica, Sans"><H3 ALIGN="LEFT">
Implementing the double dispatch</H3></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Remember that polymorphism can occur only
via method calls, so if you want double dispatching to occur, there must be two
method calls: one used to determine the type within each hierarchy. In the Trash
hierarchy there will be a new method called addToBin(&#160;), which takes an
argument of an array of TypedBin. It uses this array to step through and try to
add itself to the appropriate bin, and this is where you'll see the double
dispatch. <IMG SRC="TIPyth08.gif"></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The new hierarchy is TypedBin, and it
contains its own method called add(&#160;) that is also used polymorphically.
But here's an additional twist: add(&#160;) is overloaded to take arguments of
the different types of trash. So an essential part of the double dispatching
scheme also involves overloading.Redesigning the program produces a dilemma:
it&#146;s now necessary for the base class <B>Trash</B> to contain an
<B>addToBin(&#160;)</B> method. One approach is to copy all of the code and
change the base class. Another approach, which you can take when you don&#146;t
have control of the source code, is to put the <B>addToBin(&#160;)</B> method
into an <B>interface</B>, leave <B>Trash</B> alone, and inherit new specific
types of <B>Aluminum</B>, <B>Paper</B>, <B>Glass</B>, and <B>Cardboard</B>. This
is the approach that will be taken here.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_403">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Most of the classes in this design must
be <B>public</B>, so they are placed in their own files. Here&#146;s the
interface:
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_404">Add Comment</A></FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE># c12:doubledispatch:TypedBinMember.py
# An <font color=#0000ff>class</font> <font color=#0000ff>for</font> adding the double 
# dispatching method to the trash hierarchy 
# without modifying the original hierarchy.

<font color=#0000ff>class</font> TypedBinMember:
  # The method:
  boolean addToBin(TypedBin[] tb)
# :~</PRE></FONT></BLOCKQUOTE><DIV ALIGN="LEFT"><P><FONT FACE="Georgia">In each particular subtype of
<B>Aluminum</B>, <B>Paper</B>, <B>Glass,</B> and <B>Cardboard</B>, the
<B>addToBin(&#160;)</B> method in the <B>interface TypedBinMember</B> is
implemented, but it <I>looks</I> like the code is exactly the same in each case:
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_405">Add Comment</A></FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE># c12:doubledispatch:DDAluminum.py
# Aluminum <font color=#0000ff>for</font> double dispatching.

<font color=#0000ff>class</font> DDAluminum(Aluminum) 
    implements TypedBinMember:
  <font color=#0000ff>def</font> __init__(self, double wt): .__init__(wt) 
  <font color=#0000ff>def</font> addToBin(self, TypedBin[] tb):
    <font color=#0000ff>for</font>(int i = 0 i &lt; tb.length i++)
      <font color=#0000ff>if</font>(tb[i].add(self))
        <font color=#0000ff>return</font> 1
    <font color=#0000ff>return</font> 0

# :~</PRE></FONT></BLOCKQUOTE>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE># c12:doubledispatch:DDPaper.py
# Paper <font color=#0000ff>for</font> double dispatching.

<font color=#0000ff>class</font> DDPaper(Paper) 
    implements TypedBinMember:
  <font color=#0000ff>def</font> __init__(self, double wt): .__init__(wt) 
  <font color=#0000ff>def</font> addToBin(self, TypedBin[] tb):
    <font color=#0000ff>for</font>(int i = 0 i &lt; tb.length i++)
      <font color=#0000ff>if</font>(tb[i].add(self))
        <font color=#0000ff>return</font> 1
    <font color=#0000ff>return</font> 0

# :~</PRE></FONT></BLOCKQUOTE>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE># c12:doubledispatch:DDGlass.py
# Glass <font color=#0000ff>for</font> double dispatching.

<font color=#0000ff>class</font> DDGlass(Glass) 
    implements TypedBinMember:
  <font color=#0000ff>def</font> __init__(self, double wt): .__init__(wt) 
  <font color=#0000ff>def

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产成a人亚洲精| 日本午夜精品一区二区三区电影| 欧美美女喷水视频| 懂色av中文一区二区三区| 亚洲成av人**亚洲成av**| 国产欧美精品一区| 日韩欧美卡一卡二| 欧美色精品在线视频| 国产99一区视频免费| 日韩av电影天堂| 亚洲视频一区在线| 欧美韩日一区二区三区| 精品三级av在线| 这里只有精品电影| 色素色在线综合| av在线不卡免费看| 国产98色在线|日韩| 精品一区在线看| 热久久久久久久| 五月婷婷激情综合| 一区二区三区小说| 亚洲欧美在线高清| 中文字幕在线不卡一区 | 51精品秘密在线观看| 日本精品一区二区三区高清| 97久久精品人人做人人爽| 大尺度一区二区| 国产一二精品视频| 精品一区二区国语对白| 蜜臀av性久久久久av蜜臀妖精| 偷拍日韩校园综合在线| 亚洲一区二区三区中文字幕在线| 亚洲黄网站在线观看| 亚洲色图欧美偷拍| 欧美一级欧美三级在线观看| 欧美日韩一区二区在线观看视频 | 91亚洲精华国产精华精华液| 成人一区二区三区视频在线观看| 国产精品一区三区| 国产成人综合在线播放| 国产经典欧美精品| 粉嫩av一区二区三区在线播放 | 夜夜嗨av一区二区三区中文字幕| 亚洲免费毛片网站| 亚洲欧美日韩国产一区二区三区 | 91麻豆精品国产自产在线观看一区| 欧美亚洲图片小说| 欧美三级韩国三级日本一级| 欧美日韩免费一区二区三区 | 亚洲精品一线二线三线无人区| 欧美一级二级三级乱码| 日韩一级欧美一级| 26uuu欧美日本| 国产精品久久久久aaaa| 最新国产精品久久精品| 亚洲免费观看在线观看| 一区二区三区四区在线播放| 亚洲va韩国va欧美va精品| 午夜一区二区三区视频| 美女精品一区二区| 丰满少妇久久久久久久| av在线不卡免费看| 欧美女孩性生活视频| 日韩三级中文字幕| 国产精品视频线看| 亚洲精品国产精华液| 免费观看30秒视频久久| 国产精品99久久久久久似苏梦涵| av成人老司机| 7777精品伊人久久久大香线蕉超级流畅 | 日本中文一区二区三区| 激情丁香综合五月| 99久久综合色| 91精品国产黑色紧身裤美女| 久久婷婷国产综合精品青草 | 亚洲国产中文字幕| 国内外精品视频| 色94色欧美sute亚洲线路一久| 在线播放中文字幕一区| 国产欧美一区二区三区鸳鸯浴| 一区二区日韩电影| www.激情成人| 成人av在线播放网址| 欧美性猛交xxxxxx富婆| 精品久久久久久亚洲综合网| 中文字幕在线视频一区| 日韩专区欧美专区| 成人亚洲精品久久久久软件| 欧美美女一区二区三区| 国产精品国产精品国产专区不蜜| 亚洲成a人片在线不卡一二三区| 亚洲三级在线观看| 老司机精品视频导航| 91蜜桃婷婷狠狠久久综合9色| 91精品国产高清一区二区三区蜜臀| 国产精品网站在线播放| 日本vs亚洲vs韩国一区三区二区| k8久久久一区二区三区 | 精品91自产拍在线观看一区| 亚洲欧美视频在线观看视频| 韩国精品主播一区二区在线观看 | 99久久99久久精品免费观看| 日韩美女主播在线视频一区二区三区 | 激情都市一区二区| 欧美老人xxxx18| 亚洲人被黑人高潮完整版| 狠狠色丁香久久婷婷综合丁香| 欧美视频在线一区| 一色屋精品亚洲香蕉网站| 国产一区二区视频在线播放| 精品视频免费在线| 中文字幕一区免费在线观看| 免费观看一级特黄欧美大片| 欧美揉bbbbb揉bbbbb| 日韩一区欧美一区| 国产精品一级二级三级| 欧美大尺度电影在线| 亚洲成人一区在线| 色婷婷一区二区三区四区| 日本一区二区动态图| 韩国一区二区视频| 日韩精品一区国产麻豆| 亚洲国产精品久久久久婷婷884 | 91精品久久久久久蜜臀| 夜夜夜精品看看| 欧洲精品在线观看| 国产精品久久夜| 成+人+亚洲+综合天堂| 久久亚洲精品国产精品紫薇| 美腿丝袜亚洲三区| 欧美mv日韩mv国产网站| 老司机免费视频一区二区| 日韩免费视频一区二区| 久久成人久久爱| 精品国产成人在线影院| 久久99久久久久| 精品理论电影在线观看| 久久精品免费观看| 欧美成人性战久久| 久久av资源网| 三级在线观看一区二区| 91蝌蚪porny| 亚洲色图20p| eeuss鲁一区二区三区| 国产精品乱码人人做人人爱 | 91同城在线观看| 亚洲欧美在线高清| 欧美最猛性xxxxx直播| 亚洲国产中文字幕| 91精品一区二区三区在线观看| 亚洲综合精品自拍| 欧美肥妇毛茸茸| 成人av资源下载| 一区二区三区日韩在线观看| 7777精品伊人久久久大香线蕉完整版 | 美国十次综合导航| 亚洲精品在线观| 成人性生交大片免费看视频在线 | 不卡免费追剧大全电视剧网站| 国产精品第五页| 色综合久久精品| 亚洲成人中文在线| 欧美成人午夜电影| av毛片久久久久**hd| 香港成人在线视频| 国产午夜精品美女毛片视频| 成人做爰69片免费看网站| 一级中文字幕一区二区| 日韩一级成人av| 成人免费高清在线| 一区二区三区 在线观看视频| 欧美高清视频www夜色资源网| 久久99精品久久久久久| 国产精品欧美一区二区三区| 日本黄色一区二区| 日日夜夜精品视频免费| 欧美精品一区二区精品网| 成人涩涩免费视频| 亚洲第一成人在线| 国产三级精品三级| 欧美吞精做爰啪啪高潮| 韩国av一区二区三区四区 | 亚洲欧美日韩一区二区三区在线观看| 91豆麻精品91久久久久久| 另类综合日韩欧美亚洲| 亚洲色图欧洲色图婷婷| 日韩一区二区三区观看| www.成人网.com| 久久丁香综合五月国产三级网站| 亚洲免费观看高清完整版在线观看 | 处破女av一区二区| 日韩精品亚洲一区| 国产精品青草久久| 国产精品一区二区三区99| 国产成人99久久亚洲综合精品| 欧美乱熟臀69xxxxxx| 欧美一级搡bbbb搡bbbb| 日韩午夜激情视频| 亚洲啪啪综合av一区二区三区| 午夜在线电影亚洲一区|