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

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

?? sect05.htm

?? Pythn design pattern
?? HTM
?? 第 1 頁 / 共 4 頁
字號:
<!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:12
Translation Platform:Win32
Number of Output files:18
This File:Sect05.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>4:Fronting for an implementation</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="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>
    
  </CENTER>
  </P></DIV><A NAME="_Toc476705898"></A><A NAME="_Toc534420083"></A><A NAME="Heading34"></A><FONT FACE = "Verdana, Tahoma, Arial, Helvetica, Sans"><H1 ALIGN="LEFT">
4:Fronting for an implementation</H1></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Both <I>Proxy</I> and <I>State</I>
provide a surrogate class that you use in your code; the real class that does
the work is hidden behind this surrogate class. When you call a method in the
surrogate, it simply turns around and calls the method in the implementing
class. These two patterns are so similar that the <I>Proxy</I> is simply a
special case of <I>State</I>. One is tempted to just lump the two together into
a pattern called <I>Surrogate</I>, but the term &#147;proxy&#148; has a
long-standing and specialized meaning, which probably explains the reason for
the two different patterns.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_126">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The basic idea is simple: from a base
class, the surrogate is derived along with the class or classes that provide the
actual implementation:
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_127">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="CENTER"><FONT FACE="Georgia"><IMG SRC="TIPyth00.gif"></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">When a surrogate object is created, it is
given an implementation to which to send all of the method calls.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_128">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Structurally, the difference between
<I>Proxy</I> and <I>State</I> is simple: a <I>Proxy</I> has only one
implementation, while <I>State</I> has more than one. The application of the
patterns is considered (in <I>Design Patterns</I>) to be distinct: <I>Proxy</I>
is used to control access to its implementation, while <I>State</I> allows you
to change the implementation dynamically. However, if you expand your notion of
&#147;controlling access to implementation&#148; then the two fit neatly
together.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_129">Add Comment</A></FONT><A NAME="_Toc476705899"></A><A NAME="_Toc534420084"></A><BR></P></DIV>
<A NAME="Heading35"></A><FONT FACE = "Verdana, Tahoma, Arial, Helvetica, Sans"><H2 ALIGN="LEFT">
Proxy</H2></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">If we implement <I>Proxy</I> by following
the above diagram, it looks like this:
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_130">Add Comment</A></FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE>#: c04:ProxyDemo.py
# Simple demonstration of the Proxy pattern.

<font color=#0000ff>class</font> Implementation:
  <font color=#0000ff>def</font> f(self): 
    <font color=#0000ff>print</font> <font color=#004488>"Implementation.f()"</font>
  <font color=#0000ff>def</font> g(self): 
    <font color=#0000ff>print</font> <font color=#004488>"Implementation.g()"</font> 
  <font color=#0000ff>def</font> h(self): 
    <font color=#0000ff>print</font> <font color=#004488>"Implementation.h()"</font> 

<font color=#0000ff>class</font> Proxy:
  <font color=#0000ff>def</font> __init__(self): 
    self.__implementation = Implementation() 
  # Pass method calls to the implementation:
  <font color=#0000ff>def</font> f(self): self.__implementation.f() 
  <font color=#0000ff>def</font> g(self): self.__implementation.g() 
  <font color=#0000ff>def</font> h(self): self.__implementation.h() 

p = Proxy()
p.f(); p.g(); p.h()
#:~</PRE></FONT></BLOCKQUOTE><DIV ALIGN="LEFT"><P><FONT FACE="Georgia">It isn&#146;t necessary that
<B>Implementation</B> have the same interface as <B>Proxy</B>; as long as
<B>Proxy</B> is somehow &#147;speaking for&#148; the class that it is
referring method calls to then the basic idea is satisfied (note that this
statement is at odds with the definition for Proxy in GoF). However, it is
convenient to have a common interface so that <B>Implementation</B> is forced to
fulfill all the methods that <B>Proxy</B> needs to call.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_131">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Of course, in Python we have a delegation
mechanism built in, so it makes the <B>Proxy</B> even simpler to implement:
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_132">Add Comment</A></FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE>#: c04:ProxyDemo2.py
# Simple demonstration of the Proxy pattern.

<font color=#0000ff>class</font> Implementation2:
  <font color=#0000ff>def</font> f(self): 
    <font color=#0000ff>print</font> <font color=#004488>"Implementation.f()"</font>
  <font color=#0000ff>def</font> g(self): 
    <font color=#0000ff>print</font> <font color=#004488>"Implementation.g()"</font> 
  <font color=#0000ff>def</font> h(self): 
    <font color=#0000ff>print</font> <font color=#004488>"Implementation.h()"</font> 

<font color=#0000ff>class</font> Proxy2:
  <font color=#0000ff>def</font> __init__(self): 
    self.__implementation = Implementation2() 
  <font color=#0000ff>def</font> __getattr__(self, name):
    <font color=#0000ff>return</font> getattr(self.__implementation, name)

p = Proxy2()
p.f(); p.g(); p.h();
#:~</PRE></FONT></BLOCKQUOTE><DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The beauty of using
<B>__getattr__(&#160;)</B> is that <B>Proxy2</B> is completely generic, and not
tied to any particular implementation (in Java, a rather complicated
&#147;dynamic proxy&#148; has been invented to accomplish this same thing).
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_133">Add Comment</A></FONT><A NAME="_Toc476705900"></A><A NAME="_Toc534420085"></A><BR></P></DIV>
<A NAME="Heading36"></A><FONT FACE = "Verdana, Tahoma, Arial, Helvetica, Sans"><H2 ALIGN="LEFT">
State</H2></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The <I>State</I> pattern adds more
implementations to <I>Proxy</I>, along with a way to switch from one
implementation to another during the lifetime of the surrogate:
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_134">Add Comment</A></FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE>#: c04:StateDemo.py
# Simple demonstration of the State pattern.

<font color=#0000ff>class</font> State_d:
  <font color=#0000ff>def</font> __init__(self, imp): 
    self.__implementation = imp 
  <font color=#0000ff>def</font> changeImp(self, newImp):
    self.__implementation = newImp
  # Delegate calls to the implementation:
  <font color=#0000ff>def</font> __getattr__(self, name):
    <font color=#0000ff>return</font> getattr(self.__implementation, name)

<font color=#0000ff>class</font> Implementation1:
  <font color=#0000ff>def</font> f(self): 
    <font color=#0000ff>print</font> <font color=#004488>"Fiddle de dum, Fiddle de dee,"</font> 
  <font color=#0000ff>def</font> g(self): 
    <font color=#0000ff>print</font> <font color=#004488>"Eric the half a bee."</font> 
  <font color=#0000ff>def</font> h(self): 
    <font color=#0000ff>print</font> <font color=#004488>"Ho ho ho, tee hee hee,"</font> 

<font color=#0000ff>class</font> Implementation2:
  <font color=#0000ff>def</font> f(self): 
    <font color=#0000ff>print</font> <font color=#004488>"We're Knights of the Round Table."</font> 
  <font color=#0000ff>def</font> g(self): 
    <font color=#0000ff>print</font> <font color=#004488>"We dance whene'er we're able."</font> 
  <font color=#0000ff>def</font> h(self): 
    <font color=#0000ff>print</font> <font color=#004488>"We do routines and chorus scenes"</font> 

<font color=#0000ff>def</font> run(b):
  b.f()
  b.g()
  b.h()
  b.g()

b = State_d(Implementation1())
run(b)
b.changeImp(Implementation2())
run(b)
#:~</PRE></FONT></BLOCKQUOTE><DIV ALIGN="LEFT"><P><FONT FACE="Georgia">You can see that the first
implementation is used for a bit, then the second implementation is swapped in
and that is used.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_135">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The difference between <I>Proxy</I> and
<I>State</I> is in the problems that are solved. The common uses for
<I>Proxy</I> as described in <I>Design Patterns</I> are:
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_136">Add Comment</A></FONT><BR></P></DIV>
<OL>
<LI><FONT FACE="Verdana"><B>	</B></FONT><FONT FACE="Georgia"><B>Remote
proxy</B>. This proxies for an object in a different address space. A remote
proxy is created for you automatically by the RMI compiler <B>rmic</B> as it
creates stubs and skeletons.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_137">Add Comment</A></FONT><LI><FONT FACE="Verdana"><B>	</B></FONT><FONT FACE="Georgia"><B>Virtual
proxy</B>. This provides &#147;lazy initialization&#148; to create expensive
objects on demand.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_138">Add Comment</A></FONT><LI><FONT FACE="Verdana"><B>	</B></FONT><FONT FACE="Georgia"><B>Protection
proxy</B>. Used when you don&#146;t want the client programmer to have full
access to the proxied object.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_139">Add Comment</A></FONT><LI><FONT FACE="Verdana"><B>	</B></FONT><FONT FACE="Georgia"><B>Smart
reference</B>. To add additional actions when the proxied object is accessed.
For example, or to keep track of the number of references that are held for a
particular object, in order to implement the <I>copy-on-write</I> idiom and
prevent object aliasing. A simpler example is keeping track of the number of
calls to a particular method.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_140">Add Comment</A></FONT></OL><DIV ALIGN="LEFT"><P><FONT FACE="Georgia">You
could look at a Python reference as a kind of protection proxy, since it
controls access to the actual object on the heap (and ensures, for example, that
you don&#146;t use a <B>null </B>reference).
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_141">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">[[ Rewrite this: In <I>Design
Patterns</I>, <I>Proxy</I> and <I>State</I> are not seen as related to each
other because the two are given (what I consider arbitrarily) different
structures. <I>State</I>, in particular, uses a separate implementation
hierarchy but this seems to me to be unnecessary unless you have decided that
the implementation is not under your control (certainly a possibility, but if
you own all the code there seems to be no reason not to benefit from the
elegance and helpfulness of the single base class). In addition, <I>Proxy</I>
need not use the same base class for its implementation, as long as the proxy
object is controlling access to the object it &#147;fronting&#148; for.
Regardless of the specifics, in both <I>Proxy </I>and <I>State</I> a surrogate
is passing method calls through to an implementation object.]]]
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_142">Add Comment</A></FONT><A NAME="_Toc476705901"></A><A NAME="_Toc534420086"></A><BR></P></DIV>
<A NAME="Heading37"></A><FONT FACE = "Verdana, Tahoma, Arial, Helvetica, Sans"><H2 ALIGN="LEFT">
StateMachine</H2></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">While <I>State</I> has a way to allow the
client programmer to change the implementation, <I>StateMachine</I> imposes a
structure to automatically change the implementation from one object to the
next. The current implementation represents the state that a system is in, and
the system behaves differently from one state to the next (because it uses
<I>State</I>). Basically, this is a &#147;state machine&#148; using objects.
<A HREF="http://www.mindview.net/Books/TIPython/BackTalk/FindPage/A_143">Add Comment</A></FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The code that moves the system from one

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品视频在线| 日本中文字幕一区二区有限公司| 国产在线播精品第三| 久久免费看少妇高潮| 成人理论电影网| 自拍偷拍国产精品| 欧美成人一区二区三区片免费 | 婷婷久久综合九色国产成人 | 欧美大度的电影原声| 东方欧美亚洲色图在线| 一区二区三区高清| 国产精品久久久99| 久久亚洲捆绑美女| 91精品免费在线观看| 在线观看日韩电影| 盗摄精品av一区二区三区| 九九**精品视频免费播放| 亚洲va欧美va人人爽午夜| 成人免费视频在线观看| 国产精品女同一区二区三区| 91精品国产色综合久久不卡电影| 91捆绑美女网站| 色婷婷综合视频在线观看| 91在线云播放| 91在线观看视频| 色呦呦一区二区三区| 色综合 综合色| 欧美日韩一区二区在线视频| 色综合天天性综合| 欧洲人成人精品| 4438成人网| 国产亚洲视频系列| 欧美韩国一区二区| 亚洲欧美经典视频| 日韩电影免费在线观看网站| 亚洲成a天堂v人片| 久久国产精品色| 99re成人精品视频| 欧美亚洲另类激情小说| 欧美精品久久一区| 久久久久久久久久久久久女国产乱| 欧美精品一区二区三区高清aⅴ | 色激情天天射综合网| 欧美三级电影网站| 国产亚洲美州欧州综合国| 综合电影一区二区三区| 日韩极品在线观看| 北条麻妃一区二区三区| 精品婷婷伊人一区三区三| 精品精品国产高清一毛片一天堂| 久久免费精品国产久精品久久久久 | 婷婷久久综合九色国产成人| 精品一区二区久久| 日韩亚洲欧美在线| 亚洲男人的天堂网| 成人理论电影网| 久久久久久久性| 免费成人在线观看视频| 欧美性受xxxx黑人xyx| 国产人妖乱国产精品人妖| 日本欧美肥老太交大片| 91蝌蚪porny| 国产精品久久久久久久久久免费看 | 欧美日韩www| 亚洲狼人国产精品| 94-欧美-setu| 中文字幕一区视频| 波多野结衣视频一区| 亚洲国产高清aⅴ视频| 国产福利电影一区二区三区| 日韩一区二区精品| 久久精品国产一区二区三区免费看| 色婷婷亚洲综合| 午夜精品福利一区二区蜜股av| 91国偷自产一区二区开放时间| 一区二区三区蜜桃| 欧美一区二视频| 国产精品888| 亚洲欧美精品午睡沙发| 欧美日韩精品一区二区天天拍小说 | 欧美激情中文字幕一区二区| 国产黄色成人av| 一区二区三区视频在线看| 欧美精品在线视频| 国产麻豆91精品| 亚洲最大成人综合| 亚洲精品一区二区三区影院| 成+人+亚洲+综合天堂| 午夜婷婷国产麻豆精品| 国产日韩综合av| 欧美视频在线播放| 国产高清久久久| 午夜电影一区二区| 国产精品乱码久久久久久| 欧美人成免费网站| 成人黄色777网| 经典三级在线一区| 日本特黄久久久高潮| 亚洲免费观看高清完整版在线观看熊 | 精品久久国产字幕高潮| 日本道在线观看一区二区| 久久成人精品无人区| 午夜精彩视频在线观看不卡| 综合亚洲深深色噜噜狠狠网站| 欧美不卡123| 欧美videos中文字幕| 91精品婷婷国产综合久久性色 | 久久久99精品久久| 精品久久久久久久久久久久久久久 | 精品视频999| 欧美视频三区在线播放| 欧美日韩三级一区二区| 在线影视一区二区三区| 色综合久久99| 91美女片黄在线| 欧美高清www午色夜在线视频| 91国内精品野花午夜精品| 91免费在线播放| 欧美性视频一区二区三区| 色琪琪一区二区三区亚洲区| 色哦色哦哦色天天综合| 色一区在线观看| 制服丝袜亚洲色图| 欧美一区二区二区| 精品对白一区国产伦| 中文字幕欧美国产| 婷婷综合久久一区二区三区| 午夜精品久久久久久| 国产91对白在线观看九色| 国产91对白在线观看九色| 欧美婷婷六月丁香综合色| 日韩三级视频在线观看| 国产精品伦一区| 久久国产精品第一页| 色综合久久中文综合久久97| 欧美一级精品大片| 亚洲欧美在线aaa| 国产美女视频91| 51精品秘密在线观看| 久久精品国产亚洲一区二区三区| 97久久精品人人做人人爽50路| 日韩视频一区二区| 一区二区三区中文字幕电影| 国产凹凸在线观看一区二区| 欧美日韩精品一区二区三区四区 | 一区二区三区日本| 99麻豆久久久国产精品免费优播| 欧美日韩国产区一| 国产精品成人免费在线| 亚洲成人免费视频| 色狠狠一区二区| 国产亚洲成年网址在线观看| 日本欧美在线看| 日本美女一区二区| 国产一区二区三区在线观看免费视频| 99精品久久久久久| 久久婷婷色综合| 日韩国产欧美一区二区三区| 成人一区二区视频| 69堂亚洲精品首页| 综合网在线视频| 国产乱子轮精品视频| 欧美日韩亚洲不卡| 亚洲精品视频观看| 成人久久视频在线观看| 久久久久久久精| 久久er99热精品一区二区| 91国产免费看| 精品久久久久香蕉网| 美女网站视频久久| 欧美大白屁股肥臀xxxxxx| 午夜亚洲福利老司机| 欧美精品在线视频| 国产精品久久国产精麻豆99网站| 美女精品自拍一二三四| 欧美一区二区二区| 蜜臀av国产精品久久久久| 欧美一区二区三区系列电影| 日韩精品乱码av一区二区| 欧美日韩国产中文| 麻豆精品一区二区综合av| 精品国产乱码久久久久久闺蜜| 精品亚洲免费视频| 国产日韩欧美高清在线| 日本乱人伦一区| 国产精品亚洲视频| 亚洲码国产岛国毛片在线| 欧美精品国产精品| 成人动漫一区二区三区| 亚洲精选一二三| 日本韩国一区二区三区视频| 午夜精品成人在线视频| 日韩美女精品在线| 欧美一卡二卡在线观看| yourporn久久国产精品| 亚洲女人****多毛耸耸8| 欧美变态凌虐bdsm| 在线视频你懂得一区二区三区| 午夜伦理一区二区| 亚洲乱码中文字幕综合|