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

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

?? pat5k-1.htm

?? 四人幫《設(shè)計模式》一書英文版本
?? HTM
?? 第 1 頁 / 共 3 頁
字號:
<HTML>

<HEAD><TITLE>Visitor</TITLE>
<SCRIPT>
function setFocus() {	
	if ((navigator.appName != "Netscape") && (parseFloat(navigator.appVersion) == 2)) {
	return;
	} else {
	self.focus();
	}
}
</SCRIPT>
</HEAD>

<BODY   BGCOLOR         = #FFFFFF onLoad="setFocus()";>

<A NAME="top"></A>
<A NAME="Visitor"></A>
<A NAME="intent"></A>
<H2><A HREF="#motivation"><IMG SRC="down3-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/gifsb/down3.gif" BORDER=0 ALT="next: 
Motivation"></A> Intent</H2> 

<A NAME="auto1000"></A>
<P>Represent an operation to be performed on the elements of an object
structure.  Visitor lets you define a new operation without changing the
classes of the elements on which it operates.</P>

<A NAME="motivation"></A>
<H2><A HREF="#applicability"><IMG SRC="down3-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/gifsb/down3.gif" BORDER=0 
ALT="next: Applicability"></A> Motivation</H2> 

<A NAME="abssyntree"></A>
<P>Consider a compiler that represents programs as abstract syntax trees.
It will need to perform operations on abstract syntax trees for "static
semantic" analyses like checking that all variables are defined. It
will also need to generate code. So it might define operations for
type-checking, code optimization, flow analysis, checking for variables
being assigned values before they're used, and so on. Moreover, we could
use the abstract syntax trees for pretty-printing, program
restructuring, code instrumentation, and computing various metrics of a
program.</P>

<A NAME="auto1001"></A>
<P>Most of these operations will need to treat nodes that represent
assignment statements differently from nodes that represent variables or
arithmetic expressions. Hence there will be one class for assignment
statements, another for variable accesses, another for arithmetic
expressions, and so on. The set of node classes depends on the language
being compiled, of course, but it doesn't change much for a given
language.</P>

<A NAME="abssync"></A>
<P ALIGN=CENTER><IMG SRC="visit006-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/Pictures/visit006.gif"></P>

<A NAME="auto1002"></A>
<P>This diagram shows part of the Node class hierarchy.  The problem here
is that distributing all these operations across the various node
classes leads to a system that's hard to understand, maintain, and
change. It will be confusing to have type-checking code mixed with
pretty-printing code or flow analysis code. Moreover, adding a new
operation usually requires recompiling all of these classes. It would be
better if each new operation could be added separately, and the node
classes were independent of the operations that apply to them.</P>

<A NAME="def-visitor"></A>
<P>We can have both by packaging related operations from each class in a
separate object, called a <STRONG>visitor</STRONG>, and passing it to
elements of the abstract syntax tree as it's traversed. When an element
"accepts" the visitor, it sends a request to the visitor that encodes
the element's class. It also includes the element as an argument. The
visitor will then execute the operation for that element&#151;the
operation that used to be in the class of the element.</P>

<A NAME="typecheck"></A>
<P>For example, a compiler that didn't use visitors might type-check a
procedure by calling the TypeCheck operation on its abstract syntax
tree. Each of the nodes would implement TypeCheck by calling TypeCheck
on its components (see the preceding class diagram). If the compiler
type-checked a procedure using visitors, then it would create a
TypeCheckingVisitor object and call the Accept operation on the
abstract syntax tree with that object as an argument. Each of the
nodes would implement Accept by calling back on the visitor: an
assignment node calls VisitAssignment operation on the visitor, while
a variable reference calls VisitVariableReference. What used to be the
TypeCheck operation in class AssignmentNode is now the VisitAssignment
operation on TypeCheckingVisitor.</P>

<A NAME="auto1003"></A>
<P>To make visitors work for more than just type-checking, we need an
abstract parent class NodeVisitor for all visitors of an abstract syntax
tree. NodeVisitor must declare an operation for each node class. An
application that needs to compute program metrics will define new
subclasses of NodeVisitor and will no longer need to add
application-specific code to the node classes. The Visitor pattern
encapsulates the operations for each compilation phase in a Visitor
associated with that phase.</P>

<A NAME="332c"></A>
<P ALIGN=CENTER><IMG SRC="visit113-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/Pictures/visit113.gif"></P>

<A NAME="333c"></A>
<P ALIGN=CENTER><IMG SRC="visit112-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/Pictures/visit112.gif"></P>

<A NAME="auto1004"></A>
<P>With the Visitor pattern, you define two class hierarchies: one for the
elements being operated on (the Node hierarchy) and one for the visitors
that define operations on the elements (the NodeVisitor hierarchy). You
create a new operation by adding a new subclass to the visitor class
hierarchy. As long as the grammar that the compiler accepts doesn't
change (that is, we don't have to add new Node subclasses), we can add
new functionality simply by defining new NodeVisitor subclasses.</P>

<A NAME="applicability"></A>
<H2><A HREF="#structure"><IMG SRC="down3-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/gifsb/down3.gif" BORDER=0 ALT="next: 
Structure"></A> Applicability</H2> 

<A NAME="auto1005"></A>
<P>Use the Visitor pattern when</P>

<UL>

<A NAME="auto1006"></A>
<LI>an object structure contains many classes of objects with differing
interfaces, and you want to perform operations on these objects that
depend on their concrete classes.</LI>
<A NAME="auto1007"></A>
<P></P>
<A NAME="auto1008"></A>
<LI>many distinct and unrelated operations need to be performed on objects
in an object structure, and you want to avoid "polluting" their
classes with these operations. Visitor lets you keep related operations
together by defining them in one class. When the object structure is
shared by many applications, use Visitor to put operations in just those
applications that need them.</LI>
<A NAME="auto1009"></A>
<P></P>
<A NAME="auto1010"></A>
<LI>the classes defining the object structure rarely change, but you often
want to define new operations over the structure. Changing the object
structure classes requires redefining the interface to all visitors,
which is potentially costly. If the object structure classes change
often, then it's probably better to define the operations in those
classes.</LI>

</UL>

<A NAME="structure"></A>
<H2><A HREF="#participants"><IMG SRC="down3-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/gifsb/down3.gif" BORDER=0 ALT="next: 
Participants"></A> Structure</H2> 

<P ALIGN=CENTER><IMG SRC="visitor-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/Pictures/visitor.gif"></P>

<A NAME="participants"></A>
<H2><A HREF="#collaborations"><IMG SRC="down3-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/gifsb/down3.gif" BORDER=0 
ALT="next: Collaborations"></A> Participants</H2>

<UL>

<A NAME="auto1011"></A>
<LI><B>Visitor</B> (NodeVisitor)</LI>

<A NAME="auto1012"></A>
<P></P>

    <UL>

    <A NAME="auto1013"></A>
<LI>declares a Visit operation for each class of ConcreteElement
    in the object structure.  The operation's name and
    signature identifies the class that sends the Visit
    request to the visitor. That lets the visitor determine the
    concrete class of the element being visited.  Then the visitor
    can access the element directly through its particular interface.</LI>

    </UL>

<A NAME="auto1014"></A>
<P></P>

<A NAME="auto1015"></A>
<LI><B>ConcreteVisitor</B> (TypeCheckingVisitor)</LI>

<A NAME="auto1016"></A>
<P></P>

    <UL>

    <A NAME="auto1017"></A>
<LI>implements each operation declared by Visitor. Each operation
    implements a fragment of the algorithm defined for the corresponding
    class of object in the structure.  ConcreteVisitor provides the
    context for the algorithm and stores its local state. This state often
    accumulates results during the traversal of the structure.</LI>

    </UL>

<A NAME="auto1018"></A>
<P></P>

<A NAME="part-element"></A>
<LI><B>Element</B> (Node)</LI>

<A NAME="auto1019"></A>
<P></P>

    <UL>

    <A NAME="auto1020"></A>
<LI>defines an Accept operation that takes a visitor as an argument.</LI>

    </UL>

<A NAME="auto1021"></A>
<P></P>

<A NAME="auto1022"></A>
<LI><B>ConcreteElement</B> (AssignmentNode,VariableRefNode)</LI>

<A NAME="auto1023"></A>
<P></P>

    <UL>

    <A NAME="auto1024"></A>
<LI>implements an Accept operation that takes a visitor as an
    argument.</LI>

    </UL>

<A NAME="auto1025"></A>
<P></P>

<A NAME="auto1026"></A>
<LI><B>ObjectStructure</B> (Program)</LI>

<A NAME="auto1027"></A>
<P></P>

    <UL>

    <A NAME="auto1028"></A>
<LI>can enumerate its elements.</LI>

    <A NAME="auto1029"></A>
<P><!-- extra space --></P>

    <A NAME="auto1030"></A>
<LI>may provide a high-level interface to allow the visitor
    to visit its elements.</LI>

    <A NAME="auto1031"></A>
<P><!-- extra space --></P>

    <A NAME="auto1032"></A>
<LI>may either be a composite (see
    <A HREF="pat4cfs-1.htm" tppabs="http://ultra/development/DesignPatterns/lowres/pat4cfs.htm" TARGET="_mainDisplayFrame">Composite (163)</A>)
    or a collection such as a list or a set.</LI>

    </UL>

</UL>

<A NAME="collaborations"></A>
<H2><A HREF="#consequences"><IMG SRC="down3-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/gifsb/down3.gif" BORDER=0 
ALT="next: Consequences"></A> Collaborations</H2>

<UL>

<A NAME="auto1033"></A>
<LI>A client that uses the Visitor pattern must create a ConcreteVisitor
object and then traverse the object structure, visiting each element
with the visitor.</LI>
<A NAME="auto1034"></A>
<P></P>
<A NAME="auto1035"></A>
<LI>When an element is visited, it calls the Visitor operation that
corresponds to its class.  The element supplies itself as an argument
to this operation to let the visitor access its state, if necessary.

<A NAME="auto1036"></A>
<P>The following interaction diagram illustrates the collaborations
between an object structure, a visitor, and two elements:</P>

<P ALIGN=CENTER><IMG SRC="visit003-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/Pictures/visit003.gif"></P>

</LI>

</UL>

<A NAME="consequences"></A>
<H2><A HREF="#implementation"><IMG SRC="down3-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/gifsb/down3.gif" BORDER=0 
ALT="next: Implementation"></A> Consequences</H2> 

<A NAME="auto1037"></A>
<P>Some of the benefits and liabilities of the Visitor pattern are as follows:</P>

<OL>

<A NAME="auto1038"></A>
<LI><EM>Visitor makes adding new operations easy.</EM>
Visitors make it easy to add operations that depend on the components of
complex objects. You can define a new operation over an object structure
simply by adding a new visitor. In contrast, if you spread functionality
over many classes, then you must change each class to define a new
operation.</LI>
<A NAME="auto1039"></A>
<P></P>
<A NAME="auto1040"></A>
<LI><EM>A visitor gathers related operations and separates unrelated ones.</EM>
Related behavior isn't spread over the classes defining the object
structure; it's localized in a visitor. Unrelated sets of behavior are
partitioned in their own visitor subclasses. That simplifies both the
classes defining the elements and the algorithms defined in the
visitors. Any algorithm-specific data structures can be hidden in the
visitor.</LI>
<A NAME="auto1041"></A>
<P></P>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲国产精品一区二区久久| 色综合久久久网| 91视频xxxx| 日韩美一区二区三区| 国产精品成人免费在线| 久久国产人妖系列| 欧洲色大大久久| 专区另类欧美日韩| 国产乱妇无码大片在线观看| 欧美一区二区久久| 一区二区在线电影| 成人精品亚洲人成在线| 久久综合狠狠综合久久综合88 | 国产成人在线看| 91麻豆精品国产91久久久更新时间 | 欧美体内she精视频| 最新日韩在线视频| 国产精品一区二区在线观看不卡 | 91行情网站电视在线观看高清版| 久久久91精品国产一区二区精品 | 久久精品999| 欧美精品自拍偷拍| 亚洲aaa精品| 欧美影院一区二区| 一区二区三区精密机械公司| a4yy欧美一区二区三区| 亚洲国产精品99久久久久久久久| 国产尤物一区二区在线| 久久综合色婷婷| 紧缚捆绑精品一区二区| 日韩欧美久久久| 免费久久精品视频| 精品久久一区二区| 久草这里只有精品视频| 精品999久久久| 国产精品综合网| 国产拍揄自揄精品视频麻豆| 国产精品自拍一区| 国产日韩欧美高清| 9久草视频在线视频精品| 亚洲精品成人在线| 精品视频1区2区| 蜜臀av亚洲一区中文字幕| 欧美α欧美αv大片| 国产精品综合视频| 亚洲色图自拍偷拍美腿丝袜制服诱惑麻豆 | 免费人成网站在线观看欧美高清| 欧美精品1区2区3区| 奇米影视一区二区三区| 久久精品亚洲精品国产欧美| 不卡视频免费播放| 亚洲综合激情另类小说区| 在线不卡一区二区| 国精产品一区一区三区mba桃花 | 久久久久久久久97黄色工厂| 国产大片一区二区| 亚洲精品中文字幕在线观看| 51精品秘密在线观看| 国产suv精品一区二区883| 亚洲天堂网中文字| 欧美精品久久99久久在免费线| 美女网站色91| 亚洲色图制服诱惑| 日韩免费在线观看| 一本到不卡免费一区二区| 日本美女视频一区二区| 国产精品成人午夜| 日韩精品一区二| 91丝袜国产在线播放| 免费在线观看日韩欧美| 中文字幕日韩欧美一区二区三区| 欧美日韩精品一二三区| 成人中文字幕合集| 日韩国产高清影视| 中文字幕亚洲成人| 欧美一级黄色片| 99re在线视频这里只有精品| 精品一区二区三区香蕉蜜桃| 亚洲免费在线视频一区 二区| 欧美一级欧美三级在线观看| 99视频一区二区| 国产呦精品一区二区三区网站| 亚洲韩国精品一区| 国产精品色婷婷| 欧美videofree性高清杂交| 色诱视频网站一区| 国产+成+人+亚洲欧洲自线| 午夜免费久久看| 亚洲乱码国产乱码精品精98午夜 | 波多野结衣欧美| 丰满白嫩尤物一区二区| 日韩精品免费专区| 一区二区三区在线视频观看 | 日韩精品成人一区二区三区| 亚洲图片激情小说| 国产高清久久久| 国产成人一区在线| 91啪亚洲精品| 5858s免费视频成人| 精品国产乱码久久| 国产精品卡一卡二| 亚洲制服丝袜一区| 免费高清成人在线| 国产99久久久国产精品| 91亚洲精品一区二区乱码| 欧美乱妇15p| ww久久中文字幕| 亚洲精品五月天| 蜜臀av性久久久久蜜臀aⅴ四虎| 国产高清无密码一区二区三区| 91欧美一区二区| 91.麻豆视频| 国产精品嫩草99a| 亚洲国产精品影院| 国产福利一区在线| 欧美视频三区在线播放| 精品国产欧美一区二区| 中文字幕一区二区三| 午夜亚洲国产au精品一区二区| 韩国成人福利片在线播放| 91蝌蚪porny九色| 日韩丝袜美女视频| 日韩毛片高清在线播放| 蜜桃视频第一区免费观看| 粉嫩一区二区三区在线看| 欧美日韩一区二区在线视频| 久久久精品日韩欧美| 午夜欧美2019年伦理 | 99久久国产综合精品色伊| 欧美另类z0zxhd电影| 中文字幕欧美三区| 日韩vs国产vs欧美| 色综合天天在线| 精品国产精品网麻豆系列| 亚洲综合激情小说| 成人午夜伦理影院| 日韩精品中午字幕| 亚洲综合色网站| 成人av免费在线观看| 日韩欧美在线影院| 亚洲一卡二卡三卡四卡五卡| 国产成人高清视频| 欧美本精品男人aⅴ天堂| 亚洲一区视频在线| 91浏览器入口在线观看| 国产亚洲欧美一级| 久久99久久99| 欧美日韩免费一区二区三区| 中文字幕一区在线| 国产美女视频91| 日韩三级精品电影久久久| 亚洲一区二区三区四区五区中文| 北条麻妃一区二区三区| wwwwww.欧美系列| 麻豆精品蜜桃视频网站| 91麻豆精品久久久久蜜臀| 香蕉乱码成人久久天堂爱免费| 91麻豆免费观看| 国产精品素人视频| 国产91综合一区在线观看| 久久久精品中文字幕麻豆发布| 精品一区二区综合| 日韩精品最新网址| 九色porny丨国产精品| 日韩午夜小视频| 精品午夜久久福利影院| 久久青草国产手机看片福利盒子| 另类小说欧美激情| 精品成人在线观看| 国产一区美女在线| 国产网站一区二区三区| 国产精品系列在线观看| 中文乱码免费一区二区| 成人av综合一区| 亚洲视频免费在线观看| 91福利在线播放| 婷婷激情综合网| 日韩欧美一卡二卡| 狠狠色丁香婷婷综合| 国产偷国产偷亚洲高清人白洁| 成人午夜在线播放| 日韩一区在线免费观看| 91久久精品一区二区| 亚洲电影中文字幕在线观看| 91精品国产欧美一区二区成人 | 国产成人av自拍| 自拍偷拍国产亚洲| 欧美精品1区2区3区| 国内精品免费在线观看| 国产精品毛片a∨一区二区三区| 色综合咪咪久久| 日本中文字幕一区二区有限公司| xf在线a精品一区二区视频网站| 处破女av一区二区| 亚洲狠狠丁香婷婷综合久久久| 欧美日本不卡视频| 国产一区二区三区久久久| 亚洲欧美自拍偷拍色图| 欧美日韩dvd在线观看| 激情久久久久久久久久久久久久久久|