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

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

?? 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久久国产综合精品麻豆| 久久免费偷拍视频| 久久这里只有精品首页| 亚洲欧美日韩国产中文在线| 久久se精品一区精品二区| 91视频一区二区| 国产日产欧美一区| 精品中文字幕一区二区小辣椒| 99精品一区二区| 欧美激情中文字幕| 精品一区免费av| 欧美亚洲一区三区| 一区免费观看视频| 高清不卡一二三区| 日韩视频国产视频| 日韩国产精品91| 欧美在线观看一二区| 综合在线观看色| 成人动漫一区二区在线| 国产欧美日韩三区| 国产一区二区精品久久91| 日韩欧美一级二级| 免费一级欧美片在线观看| 欧美日本一区二区三区四区| 亚洲乱码精品一二三四区日韩在线| 国产91综合一区在线观看| 久久综合丝袜日本网| 蜜臀久久99精品久久久久久9| 欧美一区二区视频在线观看2022 | 欧美在线观看一区二区| 亚洲色图一区二区三区| 91啪亚洲精品| 亚洲乱码中文字幕| 欧美天堂一区二区三区| 亚洲国产美国国产综合一区二区| 91成人在线精品| 亚洲综合精品自拍| 8v天堂国产在线一区二区| 亚洲成人av免费| 精品免费国产一区二区三区四区| 国内精品伊人久久久久av一坑| 久久久九九九九| 99久久久精品免费观看国产蜜| 亚洲欧美日韩中文字幕一区二区三区| 91香蕉视频污在线| 亚洲午夜久久久久久久久电影网 | 国产盗摄精品一区二区三区在线 | 日韩精品一区二区三区swag| 久久爱另类一区二区小说| 久久久精品国产免大香伊| 99国产精品国产精品毛片| 一区二区三区四区乱视频| 欧美另类变人与禽xxxxx| 久久99九九99精品| 中文字幕一区二区三| 欧美日韩精品电影| 国产精品原创巨作av| 亚洲视频在线观看一区| 欧美精品丝袜中出| 国产精品一级片在线观看| 亚洲同性gay激情无套| 538prom精品视频线放| 国产精品一区二区在线观看网站| 亚洲欧美日韩国产综合在线| 91精品国产综合久久福利| 国产精品自拍三区| 亚洲国产日韩精品| 国产亚洲欧美中文| 欧美唯美清纯偷拍| 高清不卡一二三区| 青青草国产成人av片免费| 成人欧美一区二区三区视频网页| 91精品麻豆日日躁夜夜躁| 国产成人在线影院| 全部av―极品视觉盛宴亚洲| 中文字幕色av一区二区三区| 91精品久久久久久久91蜜桃 | 国产一区二区导航在线播放| 一区二区三区 在线观看视频| 久久先锋影音av| 欧美日韩国产综合一区二区| 成人福利视频在线看| 欧美a一区二区| 亚洲综合色成人| 国产精品久久久久精k8| 精品成a人在线观看| 欧美日韩国产成人在线91| 9色porny自拍视频一区二区| 日本sm残虐另类| 亚洲一区二区不卡免费| 国产精品久久久久影院色老大| 精品三级在线看| 91麻豆精品国产91久久久更新时间| 99久免费精品视频在线观看 | 蜜臀久久久久久久| 亚洲精品国产一区二区精华液| 国产视频不卡一区| 欧美成人一区二区三区片免费 | 国产欧美日本一区二区三区| 日韩视频在线你懂得| 亚洲国产精品久久久男人的天堂| 欧美一区二区三级| 成人h动漫精品| 亚洲国产精品一区二区www在线| 国产欧美日韩另类视频免费观看 | 亚洲日本va午夜在线影院| 91精品国产免费| 97久久精品人人澡人人爽| 日韩激情一二三区| 中文字幕国产精品一区二区| 精品卡一卡二卡三卡四在线| 欧美一区二区三区白人| 欧美一区二区播放| 欧美另类videos死尸| 在线精品视频免费播放| 欧美在线视频不卡| 欧美日韩精品福利| 欧美一区二区网站| 欧美不卡一区二区三区四区| 精品久久久久香蕉网| 久久精品视频一区| 国产精品色在线观看| 国产亚洲精品超碰| 国产精品毛片久久久久久久| 亚洲欧美偷拍另类a∨色屁股| 亚洲精品日韩专区silk| 国产精品996| 亚洲久本草在线中文字幕| 日韩欧美国产麻豆| 久久久久久久精| 欧美激情综合五月色丁香小说| 国产精品三级视频| 亚洲精品国产视频| 日韩影院精彩在线| 国产永久精品大片wwwapp| 老司机免费视频一区二区| 国产91精品精华液一区二区三区| 成人深夜视频在线观看| 日本道在线观看一区二区| 69av一区二区三区| 久久久国产精品午夜一区ai换脸| 国产日韩成人精品| 亚洲一区在线视频| 老司机精品视频一区二区三区| 国产91精品免费| 欧美日韩精品一区二区在线播放| 日韩视频免费观看高清在线视频| 欧美国产一区视频在线观看| 亚洲自拍都市欧美小说| 国产一区二区免费看| 在线精品观看国产| 久久综合九色综合欧美就去吻| 中文字幕欧美一| 久久国产精品99精品国产 | 一区二区三区精品在线| 青青青爽久久午夜综合久久午夜| 国产成人一区二区精品非洲| 欧美优质美女网站| 欧美激情一二三区| 日本不卡在线视频| 一本久久精品一区二区| 久久影院电视剧免费观看| 亚洲国产日韩一区二区| 粉嫩蜜臀av国产精品网站| 欧美精品 国产精品| 国产精品电影一区二区| 免费成人你懂的| 色老头久久综合| 国产精品美女久久久久久久久久久| 日本sm残虐另类| 欧美日韩一二区| 综合色天天鬼久久鬼色| 国产一区二区不卡在线| 欧美另类一区二区三区| 亚洲精品国产无天堂网2021| a级精品国产片在线观看| 久久久久免费观看| 日本一区中文字幕| 欧美婷婷六月丁香综合色| 亚洲三级理论片| 成人av电影在线观看| 国产人成一区二区三区影院| 精品影视av免费| 精品日韩一区二区三区| 免费高清成人在线| 91精品欧美福利在线观看| 香蕉影视欧美成人| 欧美日韩一本到| 香港成人在线视频| 欧美老年两性高潮| 亚洲高清在线视频| 欧美日韩在线播放三区| 亚洲综合av网| 欧美日韩1区2区| 婷婷国产v国产偷v亚洲高清| 欧美美女直播网站| 日日夜夜免费精品| 欧美成人伊人久久综合网| 精品在线免费视频| 久久久.com|