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

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

?? pat5k-1.htm

?? 四人幫《設計模式》一書英文版本
?? 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>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲va欧美va天堂v国产综合| xnxx国产精品| 久久综合一区二区| 亚洲人成亚洲人成在线观看图片| 免费观看一级欧美片| 99视频超级精品| 欧美大片一区二区三区| 亚洲一区二区三区视频在线播放 | 日本不卡不码高清免费观看| 成人国产精品免费观看动漫| 欧美精品久久天天躁| 国产精品久久久99| 国产一区二区91| 7777精品伊人久久久大香线蕉最新版| 久久久精品国产免大香伊| 日本不卡一二三区黄网| 欧美日韩国产乱码电影| 日韩一区在线播放| 成人av在线影院| 欧美极品另类videosde| 国产一区二区三区在线观看精品| 欧美日韩高清在线| 亚洲成人在线观看视频| 在线观看区一区二| 综合激情成人伊人| 成人av第一页| 中文字幕欧美一区| a亚洲天堂av| 国产精品久久久久婷婷二区次| 国内精品国产成人| 欧美大片拔萝卜| 秋霞午夜av一区二区三区| 欧美日韩亚洲综合在线| 亚洲综合男人的天堂| 在线精品视频一区二区三四 | 久久综合九色综合欧美98 | 亚洲欧美一区二区三区孕妇| 99视频一区二区| 亚洲黄色性网站| 欧美日韩黄视频| 五月综合激情网| 91精品国产一区二区三区| 日韩中文欧美在线| 337p亚洲精品色噜噜噜| 捆绑调教一区二区三区| 久久视频一区二区| 国产99久久久国产精品免费看| 久久理论电影网| a级高清视频欧美日韩| 一区二区三区在线视频免费观看| 日本精品裸体写真集在线观看 | 91麻豆精品国产91久久久资源速度 | 国产毛片精品视频| 国产精品免费观看视频| 色久综合一二码| 日韩av在线发布| 国产欧美一区二区精品久导航| 国产99精品国产| 一区二区成人在线| 日韩一区二区三区视频在线观看 | 性做久久久久久| 2023国产精品视频| 99精品欧美一区二区三区小说 | 成人av电影免费观看| 夜夜嗨av一区二区三区中文字幕| 欧美日韩电影一区| 国产一区二区中文字幕| 亚洲精品国产一区二区精华液| 欧美日韩电影在线播放| 国产成人在线影院| 三级不卡在线观看| 国产精品久久久久一区二区三区共 | 天天综合日日夜夜精品| 国产喷白浆一区二区三区| 色欧美乱欧美15图片| 麻豆精品一区二区综合av| 中日韩av电影| 日韩一区二区三区在线| 97久久超碰国产精品| 免费的成人av| 亚洲免费在线电影| 精品国产免费久久 | 成年人午夜久久久| 男男成人高潮片免费网站| 国产精品福利av| 精品奇米国产一区二区三区| 色网站国产精品| 国产91丝袜在线观看| 日韩中文欧美在线| 亚洲精品高清视频在线观看| 久久久久久久电影| 欧美一卡二卡三卡| 色婷婷av一区二区三区之一色屋| 国产一区免费电影| 日本成人在线不卡视频| 一区二区激情视频| 亚洲视频一二三| 久久久激情视频| 欧美成人精品高清在线播放| 欧美日韩情趣电影| 欧美性感一类影片在线播放| 成人免费福利片| 国产成人亚洲精品狼色在线| 老司机一区二区| 人人爽香蕉精品| 五月综合激情日本mⅴ| 一区二区三区美女视频| 国产精品视频线看| 国产精品二三区| 中文字幕一区免费在线观看| 国产午夜亚洲精品羞羞网站| 日韩精品专区在线影院重磅| 制服丝袜中文字幕一区| 欧美欧美欧美欧美| 91精品国产综合久久精品性色 | 日韩avvvv在线播放| 亚洲欧美综合在线精品| 国产精品久久久久久久久免费桃花 | 久久精品欧美日韩精品| 精品成人a区在线观看| 精品国产一区二区三区久久影院 | 亚洲欧美偷拍三级| 国产精品久久久久影院亚瑟 | 成人精品在线视频观看| 国产精品私人自拍| 中文字幕乱码亚洲精品一区| 国产天堂亚洲国产碰碰| 国产日韩欧美麻豆| 国产三级精品三级在线专区| 久久精品一区二区三区不卡 | 日韩欧美在线1卡| 日韩精品一区二区三区三区免费| 日韩欧美一区二区不卡| 久久精品网站免费观看| 国产欧美久久久精品影院| 国产精品久久久久永久免费观看| 中文字幕一区二区不卡| 亚洲一级片在线观看| 亚洲高清在线精品| 美日韩一级片在线观看| 国产成人午夜精品5599| 一本色道久久综合亚洲aⅴ蜜桃| 欧美综合在线视频| 欧美高清视频www夜色资源网| 日韩一区二区视频在线观看| 久久久久久黄色| 一区二区三区欧美| 黄色精品一二区| 99精品热视频| 欧美v日韩v国产v| 国产精品大尺度| 裸体健美xxxx欧美裸体表演| 盗摄精品av一区二区三区| 欧美性videosxxxxx| 欧美大片免费久久精品三p| 一区精品在线播放| 天天射综合影视| 99久久婷婷国产综合精品电影| 欧美日韩国产片| 国产精品久久久久婷婷二区次| 午夜欧美大尺度福利影院在线看| 国产高清不卡一区二区| 欧美日韩综合色| 亚洲视频免费在线| 激情图区综合网| 欧美人与z0zoxxxx视频| 国产精品二区一区二区aⅴ污介绍| 日韩精品乱码av一区二区| 成人av手机在线观看| 精品国产91洋老外米糕| 天天色天天操综合| 日本韩国精品在线| 国产精品美日韩| 国产美女精品人人做人人爽| 制服.丝袜.亚洲.另类.中文| 亚洲精品美腿丝袜| 成人网在线播放| 精品国产亚洲在线| 日本中文字幕一区二区视频 | 69久久99精品久久久久婷婷| 亚洲精品欧美二区三区中文字幕| 国内成+人亚洲+欧美+综合在线 | 欧美国产一区二区| 久色婷婷小香蕉久久| 欧美亚洲国产一区二区三区| 国产精品免费免费| 成人午夜激情影院| 中文av一区二区| 国产成人精品一区二| 久久午夜老司机| 韩国精品在线观看| 亚洲精品在线三区| 九九热在线视频观看这里只有精品 | 国产福利一区二区三区视频在线| 日本韩国精品在线| 一区二区三区在线免费播放| 99re视频精品| 精品日产卡一卡二卡麻豆| 亚洲一区在线观看免费 | 国产麻豆精品久久一二三|