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

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

?? sect05.htm

?? Pythn design pattern
?? HTM
?? 第 1 頁 / 共 4 頁
字號:
  <font color=#0000ff>def</font> __init__(self, name, value):
    self.name = name
    self.value = value
  <font color=#0000ff>def</font> __str__(self): <font color=#0000ff>return</font> self.name 
  <font color=#0000ff>def</font> getValue(self): <font color=#0000ff>return</font> self.value 

Money.quarter = Money(<font color=#004488>"Quarter"</font>, 25)
Money.dollar = Money(<font color=#004488>"Dollar"</font>, 100)

<font color=#0000ff>class</font> Quit:
  <font color=#0000ff>def</font> __str__(self): <font color=#0000ff>return</font> <font color=#004488>"Quit"</font> 

Quit.quit = Quit()

<font color=#0000ff>class</font> Digit:
  <font color=#0000ff>def</font> __init__(self, name, value):
    self.name = name
    self.value = value
  <font color=#0000ff>def</font> __str__(self): <font color=#0000ff>return</font> self.name 
  <font color=#0000ff>def</font> getValue(self): <font color=#0000ff>return</font> self.value 
  
<font color=#0000ff>class</font> FirstDigit(Digit): <font color=#0000ff>pass</font>
FirstDigit.A = FirstDigit(<font color=#004488>"A"</font>, 0)
FirstDigit.B = FirstDigit(<font color=#004488>"B"</font>, 1)
FirstDigit.C = FirstDigit(<font color=#004488>"C"</font>, 2)
FirstDigit.D = FirstDigit(<font color=#004488>"D"</font>, 3)

<font color=#0000ff>class</font> SecondDigit(Digit): <font color=#0000ff>pass</font>
SecondDigit.one = SecondDigit(<font color=#004488>"one"</font>, 0)
SecondDigit.two = SecondDigit(<font color=#004488>"two"</font>, 1)
SecondDigit.three = SecondDigit(<font color=#004488>"three"</font>, 2)
SecondDigit.four = SecondDigit(<font color=#004488>"four"</font>, 3)

<font color=#0000ff>class</font> ItemSlot:
  id = 0
  <font color=#0000ff>def</font> __init__(self, price, quantity):
    self.price = price
    self.quantity = quantity
  <font color=#0000ff>def</font> __str__(self): <font color=#0000ff>return</font> &#180;ItemSlot.id&#180;
  <font color=#0000ff>def</font> getPrice(self): <font color=#0000ff>return</font> self.price 
  <font color=#0000ff>def</font> getQuantity(self): <font color=#0000ff>return</font> self.quantity 
  <font color=#0000ff>def</font> decrQuantity(self): self.quantity -= 1

<font color=#0000ff>class</font> VendingMachine(StateMachine):
  changeAvailable = ChangeAvailable()
  amount = 0
  FirstDigit first = null
  ItemSlot[][] items = ItemSlot[4][4]

  # Conditions:
  <font color=#0000ff>def</font> notEnough(self, input):
    i1 = first.getValue()
    i2 = input.getValue()
    <font color=#0000ff>return</font> items[i1][i2].getPrice() &gt; amount

  <font color=#0000ff>def</font> itemAvailable(self, input):
    i1 = first.getValue()
    i2 = input.getValue()
    <font color=#0000ff>return</font> items[i1][i2].getQuantity() &gt; 0

  <font color=#0000ff>def</font> itemNotAvailable(self, input):
    <font color=#0000ff>return</font> !itemAvailable.condition(input)
    #i1 = first.getValue()
    #i2 = input.getValue()
    #<font color=#0000ff>return</font> items[i1][i2].getQuantity() == 0

  # Transitions:
  <font color=#0000ff>def</font> clearSelection(self, input):
    i1 = first.getValue()
    i2 = input.getValue()
    ItemSlot <font color=#0000ff>is</font> = items[i1][i2]
    <font color=#0000ff>print</font> (
      <font color=#004488>"Clearing selection: item "</font> + <font color=#0000ff>is</font> +
      <font color=#004488>" costs "</font> + <font color=#0000ff>is</font>.getPrice() +
      <font color=#004488>" and has quantity "</font> + <font color=#0000ff>is</font>.getQuantity())
    first = null

  <font color=#0000ff>def</font> dispense(self, input):
    i1 = first.getValue()
    i2 = input.getValue()
    ItemSlot <font color=#0000ff>is</font> = items[i1][i2]
    <font color=#0000ff>print</font> (<font color=#004488>"Dispensing item "</font> + 
      <font color=#0000ff>is</font> + <font color=#004488>" costs "</font> + <font color=#0000ff>is</font>.getPrice() +
      <font color=#004488>" and has quantity "</font> + <font color=#0000ff>is</font>.getQuantity())
    items[i1][i2].decrQuantity()
    <font color=#0000ff>print</font> (<font color=#004488>"Quantity "</font> + 
      <font color=#0000ff>is</font>.getQuantity())
    amount -= <font color=#0000ff>is</font>.getPrice()
    <font color=#0000ff>print</font>(<font color=#004488>"Amount remaining "</font> + 
      amount)

  <font color=#0000ff>def</font> showTotal(self, input):
    amount += ((Money)input).getValue()
    <font color=#0000ff>print</font> <font color=#004488>"Total amount = "</font> + amount

  <font color=#0000ff>def</font> returnChange(self, input):
    <font color=#0000ff>print</font> <font color=#004488>"Returning "</font> + amount
    amount = 0

  <font color=#0000ff>def</font> showDigit(self, input):
    first = (FirstDigit)input
    <font color=#0000ff>print</font> <font color=#004488>"First Digit= "</font>+ first

  <font color=#0000ff>def</font> __init__(self):
    StateMachine.__init__(self, State.quiescent)
    <font color=#0000ff>for</font>(int i = 0 i &lt; items.length i++)
      <font color=#0000ff>for</font>(int j = 0 j &lt; items[i].length j++)
        items[i][j] = ItemSlot((j+1)*25, 5)
    items[3][0] = ItemSlot(25, 0)
    buildTable(Object[][][]{
     ::State.quiescent, # Current state
        # Input, test, transition, next state:
       :Money.<font color=#0000ff>class</font>, null, 
         showTotal, State.collecting,
     ::State.collecting, # Current state
        # Input, test, transition, next state:
       :Quit.quit, null, 
         returnChange, State.quiescent,
       :Money.<font color=#0000ff>class</font>, null, 
         showTotal, State.collecting,
       :FirstDigit.<font color=#0000ff>class</font>, null, 
         showDigit, State.selecting,
     ::State.selecting, # Current state
        # Input, test, transition, next state:
       :Quit.quit, null, 
         returnChange, State.quiescent,
       :SecondDigit.<font color=#0000ff>class</font>, notEnough, 
         clearSelection, State.collecting,
       :SecondDigit.<font color=#0000ff>class</font>, itemNotAvailable, 
         clearSelection, State.unavailable,
       :SecondDigit.<font color=#0000ff>class</font>, itemAvailable, 
         dispense, State.wantMore,
     ::State.unavailable, # Current state
        # Input, test, transition, next state:
       :Quit.quit, null, 
         returnChange, State.quiescent,
       :FirstDigit.<font color=#0000ff>class</font>, null, 
         showDigit, State.selecting,
     ::State.wantMore, # Current state
        # Input, test, transition, next state:
       :Quit.quit, null, 
         returnChange, State.quiescent,
       :FirstDigit.<font color=#0000ff>class</font>, null, 
         showDigit, State.selecting,
    )

# :~</PRE></FONT></BLOCKQUOTE><DIV ALIGN="LEFT"><P><A NAME="_Toc534420094"></A><BR></P></DIV>
<A NAME="Heading45"></A><FONT FACE = "Verdana, Tahoma, Arial, Helvetica, Sans"><H3 ALIGN="LEFT">
Testing the machine</H3></FONT>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE># c04:vendingmachine:VendingMachineTest.py
# Demonstrates use of StateMachine.py

vm = VendingMachine()
<font color=#0000ff>for</font> input <font color=#0000ff>in</font> [  
    Money.quarter,
    Money.quarter,
    Money.dollar,
    FirstDigit.A,
    SecondDigit.two,
    FirstDigit.A,
    SecondDigit.two,
    FirstDigit.C,
    SecondDigit.three,
    FirstDigit.D,
    SecondDigit.one,
    Quit.quit]:
  vm.nextState(input)

# :~</PRE></FONT></BLOCKQUOTE><DIV ALIGN="LEFT"><P><A NAME="_Toc534420095"></A><BR></P></DIV>
<A NAME="Heading46"></A><FONT FACE = "Verdana, Tahoma, Arial, Helvetica, Sans"><H2 ALIGN="LEFT">
Tools</H2></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Another approach, as your state machine
gets bigger, is to use an automation tool whereby you configure a table and let
the tool generate the state machine code for you. This can be created yourself
using a language like Python, but there are also free, open-source tools such as
<I>Libero</I>, at <A HREF="http://www.imatix.com">http://www.imatix.com</A>.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_189">Add Comment</A></FONT><A NAME="_Toc534420096"></A><BR></P></DIV>
<A NAME="Heading47"></A><FONT FACE = "Verdana, Tahoma, Arial, Helvetica, Sans"><H2 ALIGN="LEFT">
Exercises</H2></FONT>
<OL>
<LI><FONT FACE="Verdana">	</FONT><FONT FACE="Georgia">Create an example of the
&#147;virtual proxy.&#148;
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_190">Add Comment</A></FONT><LI><FONT FACE="Verdana">	</FONT><FONT FACE="Georgia">Create
an example of the &#147;Smart reference&#148; proxy where you keep count of
the number of method calls to a particular object.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_191">Add Comment</A></FONT><LI><FONT FACE="Verdana">	</FONT><FONT FACE="Georgia">Create
a program similar to certain DBMS systems that only allow a certain number of
connections at any time. To implement this, use a singleton-like system that
controls the number of &#147;connection&#148; objects that it creates. When a
user is finished with a connection, the system must be informed so that it can
check that connection back in to be reused. To guarantee this, provide a proxy
object instead of a reference to the actual connection, and design the proxy so
that it will cause the connection to be released back to the system.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_192">Add Comment</A></FONT><LI><FONT FACE="Verdana">	</FONT><FONT FACE="Georgia">Using
the <I>State</I>,<I> </I>make a class called <B>UnpredictablePerson</B> which
changes the kind of response to its <B>hello(&#160;)</B> method depending on
what kind of <B>Mood</B> it&#146;s in. Add an additional kind of <B>Mood</B>
called <B>Prozac</B>.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_193">Add Comment</A></FONT><LI><FONT FACE="Verdana">	</FONT><FONT FACE="Georgia">Create
a simple copy-on write implementation.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_194">Add Comment</A></FONT><LI><FONT FACE="Verdana">	</FONT><FONT FACE="Georgia">Apply
<B>TransitionTable.py</B> to the &#147;Washer&#148; problem.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_195">Add Comment</A></FONT><LI><FONT FACE="Verdana">	</FONT><FONT FACE="Georgia">Create
a <I>StateMachine</I> system whereby the current state along with input
information determines the next state that the system will be in. To do this,
each state must store a reference back to the proxy object (the state
controller) so that it can request the state change. Use a <B>HashMap</B> to
create a table of states, where the key is a <B>String</B> naming the new state
and the value is the new state object. Inside each state subclass override a
method <B>nextState(&#160;)</B> that has its own state-transition table. The
input to <B>nextState(&#160;)</B> should be a single word that comes from a text
file containing one word per line.<B>
</B><A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_196">Add Comment</A></FONT><LI><FONT FACE="Verdana">	</FONT><FONT FACE="Georgia">Modify
the previous exercise so that the state machine can be configured by
creating/modifying a single multi-dimensional array.<B>
</B><A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_197">Add Comment</A></FONT><LI><FONT FACE="Verdana">	</FONT><FONT FACE="Georgia">Modify
the &#147;mood&#148; exercise from the previous session so that it becomes a
state machine using StateMachine.java
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_198">Add Comment</A></FONT><LI><FONT FACE="Verdana">	</FONT><FONT FACE="Georgia">Create
an elevator state machine system using StateMachine.java
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_199">Add Comment</A></FONT><LI><FONT FACE="Verdana">	</FONT><FONT FACE="Georgia">Create
a heating/air-conditioning system using StateMachine.java<B>
</B><A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_200">Add Comment</A></FONT><LI><FONT FACE="Verdana">	</FONT><FONT FACE="Georgia">A
<I>generator</I> is an object that produces other objects, just like a factory,
except that the generator function doesn&#146;t require any arguments. Create a
<B>MouseMoveGenerator</B> which produces correct <B>MouseMove</B> actions as
outputs each time the generator function is called (that is, the mouse must move
in the proper sequence, thus the possible moves are based on the previous move
&#150; it&#146;s another state machine). Add a method <B>iterator(&#160;)
</B>to produce an iterator, but this method should take an <B>int</B> argument
that specifies the number of moves to produce before <B>hasNext(&#160;)</B>
returns <B>false</B>.<B>
</B><A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_201">Add Comment</A></FONT></OL>
<HR><DIV ALIGN="LEFT"><P><A NAME="fn13" HREF="#fnB13">[13]</A><FONT FACE="Georgia"> No
mice were harmed in the creation of this example.</FONT><BR></P></DIV>

<DIV ALIGN="CENTER">
    <FONT FACE="Verdana, Tahoma, Arial, Helvetica, Sans" size = "-1">
     [ <a href="Sect04.htm">Previous Chapter</a> ] 
    
    [ <a href="javascript:window.location.href = 'Index.htm';">Table of Contents</a> ] 
  
        [ <a href="DocIdx.htm">Index</a> ]
        
     [ <a href="Sect06.htm">Next Chapter</a> ] 
    </FONT>
    <BR>
 Last Update:12/31/2001</P></DIV>

</BODY>

</HTML>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩精品欧美日韩精品| www.一区二区| 精品一区中文字幕| 国产91对白在线观看九色| 色欧美日韩亚洲| 欧美国产日本视频| 日韩电影一区二区三区四区| 石原莉奈一区二区三区在线观看| 99精品1区2区| 欧美一卡二卡三卡| 亚洲国产欧美在线| 国产不卡在线视频| 日韩欧美一级二级| 国产欧美日韩不卡免费| 蜜臀99久久精品久久久久久软件 | 日本一区二区三区久久久久久久久不| 亚洲最新视频在线播放| 国产麻豆精品在线| 日韩欧美在线网站| 亚洲一二三四在线| 成人高清在线视频| 亚洲国产精品99久久久久久久久 | 激情五月播播久久久精品| 91久久国产综合久久| 国产精品久久久久久久第一福利| 麻豆一区二区在线| 欧日韩精品视频| 亚洲特黄一级片| 激情久久五月天| 91.com在线观看| 性感美女久久精品| 欧美一区二区三区在线观看 | 国产老女人精品毛片久久| 欧美日韩久久一区二区| 亚洲一区二区中文在线| 一本色道久久综合亚洲aⅴ蜜桃| 国产视频一区在线观看| 国产传媒欧美日韩成人| 精品国产三级a在线观看| 一区二区三区四区亚洲| 一本一本大道香蕉久在线精品| 国产精品丝袜久久久久久app| 岛国精品在线观看| 中文字幕成人在线观看| 91网站黄www| 亚洲天堂网中文字| 在线免费一区三区| 婷婷六月综合网| 欧美久久久影院| 国产一区二三区好的| 久久亚洲一级片| 天天av天天翘天天综合网色鬼国产| 91.成人天堂一区| 久久国产夜色精品鲁鲁99| 久久久高清一区二区三区| 国产成人精品亚洲777人妖| 精品视频一区三区九区| 久久精品72免费观看| 久久这里都是精品| 色综合一区二区三区| 亚洲激情校园春色| 日韩一区国产二区欧美三区| 狠狠色狠狠色综合系列| 久久综合狠狠综合| 在线免费亚洲电影| 蜜臀av性久久久久av蜜臀妖精| 日本一区免费视频| 在线影院国内精品| 亚洲一区二区三区四区在线免费观看 | 成人免费看片app下载| 色噜噜狠狠成人网p站| 日产国产欧美视频一区精品| 日韩女同互慰一区二区| 91一区一区三区| 亚洲午夜视频在线| 欧美日韩亚洲高清一区二区| 国产成人在线视频免费播放| 亚洲日本青草视频在线怡红院| 3d成人动漫网站| 福利一区二区在线观看| 亚洲欧洲精品成人久久奇米网| 欧美色图一区二区三区| 韩国av一区二区三区| 五月婷婷激情综合| 欧美国产成人在线| 欧美成人精品高清在线播放| 97超碰欧美中文字幕| 日韩二区三区在线观看| 亚洲精品国久久99热| 欧美电影免费观看高清完整版在| 欧美三级韩国三级日本三斤| 狠狠色综合日日| 国产精品婷婷午夜在线观看| 日韩欧美亚洲一区二区| av一区二区三区黑人| 国产精品一区二区视频| 亚洲午夜激情网页| 亚洲欧洲另类国产综合| 久久久影视传媒| 欧美一区二区三区成人| 成人av在线资源网站| 久久不见久久见免费视频7| 亚洲丝袜另类动漫二区| 国产精品福利影院| 精品国产伦一区二区三区观看体验| 欧美老人xxxx18| 一本色道久久加勒比精品| av激情综合网| 国产精品亚洲视频| 日韩国产欧美视频| 日韩av中文字幕一区二区三区| 亚洲欧美激情插| 亚洲精品国产精华液| 亚洲欧美一区二区视频| 亚洲欧洲日韩av| 欧美激情一区二区在线| 欧美一区二区三区不卡| 欧美日韩黄视频| av一区二区三区四区| 色综合久久88色综合天天6| 99在线精品观看| 97国产精品videossex| a4yy欧美一区二区三区| 成人动漫一区二区三区| 成人av网址在线| 国内成人精品2018免费看| 国产一区二区三区在线观看精品| 久久av资源站| 国产不卡视频在线播放| 国产精品99久| 99久久精品免费| 一本大道av伊人久久综合| 91浏览器入口在线观看| 91在线云播放| 欧美日韩在线观看一区二区| 日韩一区二区精品葵司在线| 欧美人妇做爰xxxⅹ性高电影| 欧美一区二区精品| 精品久久99ma| 中文字幕一区二区三| 最新国产精品久久精品| 亚洲欧洲性图库| 亚洲成av人片| 午夜精品一区在线观看| 看电视剧不卡顿的网站| 国产一区二区免费看| 成人国产一区二区三区精品| 日本道精品一区二区三区| 在线欧美小视频| 日韩视频永久免费| 国产拍揄自揄精品视频麻豆| 久久综合狠狠综合久久综合88 | 91极品视觉盛宴| 欧美三级视频在线观看| 精品噜噜噜噜久久久久久久久试看| 精品乱人伦一区二区三区| 日韩精品最新网址| 国产精品久久毛片a| 亚洲va欧美va人人爽午夜 | 91精品国产欧美一区二区18 | 亚洲成av人片观看| 成人精品视频一区二区三区| 色屁屁一区二区| 国产日本一区二区| 一级做a爱片久久| 成人综合在线网站| 欧美视频在线一区二区三区| 国产偷v国产偷v亚洲高清| 亚洲va欧美va国产va天堂影院| 免费美女久久99| 91年精品国产| 欧美日韩成人一区| 国产精品美日韩| 日韩高清不卡一区| 欧美羞羞免费网站| 国产欧美va欧美不卡在线| 免费欧美在线视频| 91免费精品国自产拍在线不卡| 久久久天堂av| 免费观看一级特黄欧美大片| 91成人在线免费观看| 久久人人97超碰com| 日本不卡在线视频| 日本韩国一区二区三区| 亚洲人成网站影音先锋播放| 美美哒免费高清在线观看视频一区二区 | 久久精品视频免费| 秋霞av亚洲一区二区三| 色综合一个色综合亚洲| 国产精品久久久久aaaa樱花| 精品一区二区日韩| 一本大道久久a久久精品综合| 日韩美女啊v在线免费观看| 精品系列免费在线观看| 欧美大片日本大片免费观看| 夜夜亚洲天天久久| 欧美视频一区二区在线观看| 国产精品不卡视频| 91在线视频免费观看| 中日韩av电影|