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

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

?? pat5k-1.htm

?? 四人幫《設(shè)計模式》一書英文版本
?? HTM
?? 第 1 頁 / 共 3 頁
字號:
        virtual void VisitCard(Card*);
        virtual void VisitChassis(Chassis*);
        virtual void VisitBus(Bus*);
    
        // and so on for other concrete subclasses of Equipment
    protected:
        EquipmentVisitor();
    };
</PRE>

<A NAME="auto1069"></A>
<P><CODE>Equipment</CODE> subclasses define <CODE>Accept</CODE> in
basically the same way: It calls the
<CODE>EquipmentVisitor</CODE> operation that corresponds to the class
that received the <CODE>Accept</CODE> request, like this:</P>

<A NAME="auto1070"></A>
<PRE>
    void FloppyDisk::Accept (EquipmentVisitor&amp; visitor) {
       visitor.VisitFloppyDisk(this);
    }
</PRE>

<A NAME="auto1071"></A>
<P>Equipment that contains other equipment (in particular, subclasses of
<CODE>CompositeEquipment</CODE> in the Composite pattern) implements
<CODE>Accept</CODE> by iterating over its children and calling
<CODE>Accept</CODE> on each of them. Then it calls the
<CODE>Visit</CODE> operation as usual.
For example, <CODE>Chassis::Accept</CODE> could traverse
all the parts in the chassis as follows:</P>

<A NAME="auto1072"></A>
<PRE>
    void Chassis::Accept (EquipmentVisitor&amp; visitor) {
        for (
            ListIterator<Equipment*> i(_parts);
            !i.IsDone();
            i.Next()
        ) {
            i.CurrentItem()->Accept(visitor);
        }
        visitor.VisitChassis(this);
    }
</PRE>

<A NAME="pricingvisitor"></A>
<P>Subclasses of <CODE>EquipmentVisitor</CODE> define particular algorithms
over the equipment structure. The <CODE>PricingVisitor</CODE> computes the
cost of the equipment structure. It computes the net price of all simple
equipment (e.g., floppies) and the discount price of all composite
equipment (e.g., chassis and buses).</P>

<A NAME="auto1073"></A>
<PRE>
    class PricingVisitor : public EquipmentVisitor {
    public:
        PricingVisitor();
    
        Currency&amp; GetTotalPrice();
    
        virtual void VisitFloppyDisk(FloppyDisk*);
        virtual void VisitCard(Card*);
        virtual void VisitChassis(Chassis*);
        virtual void VisitBus(Bus*);
        // ...
    private:
        Currency _total;
    };
    
    void PricingVisitor::VisitFloppyDisk (FloppyDisk* e) {
        _total += e->NetPrice();
    }
    
    void PricingVisitor::VisitChassis (Chassis* e) {
        _total += e->DiscountPrice();
    }
</PRE>

<A NAME="auto1074"></A>
<P><CODE>PricingVisitor</CODE> will compute the total cost of all nodes in the
equipment structure. Note that <CODE>PricingVisitor</CODE> chooses the
appropriate pricing policy for a class of equipment by dispatching to
the corresponding member function. What's more, we can change the
pricing policy of an equipment structure just by changing the
<CODE>PricingVisitor</CODE> class.</P>

<A NAME="auto1075"></A>
<P>We can define a visitor for computing inventory like this:

<A NAME="auto1076"></A>
<PRE>
    class InventoryVisitor : public EquipmentVisitor {
    public:
        InventoryVisitor();
    
        Inventory&amp; GetInventory();
    
        virtual void VisitFloppyDisk(FloppyDisk*);
        virtual void VisitCard(Card*);
        virtual void VisitChassis(Chassis*);
        virtual void VisitBus(Bus*);
        // ...
    
    private:
        Inventory _inventory;
    };
</PRE>

<A NAME="auto1077"></A>
<P>The <CODE>InventoryVisitor</CODE> accumulates the totals for each type of
equipment in the object structure. <CODE>InventoryVisitor</CODE> uses an
<CODE>Inventory</CODE> class that defines an interface for adding equipment
(which we won't bother defining here).</P>

<A NAME="auto1078"></A>
<PRE>
    void InventoryVisitor::VisitFloppyDisk (FloppyDisk* e) {
        _inventory.Accumulate(e);
    }
    
    void InventoryVisitor::VisitChassis (Chassis* e) {
        _inventory.Accumulate(e);
    }
</PRE>

<A NAME="auto1079"></A>
<P>Here's how we can use an <CODE>InventoryVisitor</CODE> on an
equipment structure:</P>

<A NAME="auto1080"></A>
<PRE>
    Equipment* component;
    InventoryVisitor visitor;
    
    component->Accept(visitor);
    cout &lt;&lt; "Inventory "
         &lt;&lt; component->Name()
         &lt;&lt; visitor.GetInventory();
</PRE>

<A NAME="auto1081"></A>
<P>Now we'll show how to implement the Smalltalk example from the Interpreter
pattern (see
<A HREF="pat5cfs-1.htm#Smalltalk_example_in_Interpreter" tppabs="http://ultra/development/DesignPatterns/lowres/pat5cfs.htm#Smalltalk_example_in_Interpreter" TARGET="_mainDisplayFrame">page 248</A>) with the
Visitor pattern. Like the previous example, this one is so small that
Visitor probably won't buy us much, but it provides a good illustration of
how to use the pattern. Further, it illustrates a situation in which
iteration is the visitor's responsibility.</P>

<A NAME="auto1082"></A>
<P>The object structure (regular expressions) is made of four classes,
and all of them have an <CODE>accept:</CODE> method that takes the
visitor as an argument.  In class <CODE>SequenceExpression</CODE>, the
<CODE>accept:</CODE> method is</P>

<A NAME="auto1083"></A>
<PRE>
    accept: aVisitor
         ^ aVisitor visitSequence: self
</PRE>

<A NAME="altexp"></A>
<A NAME="literalexp"></A>
<A NAME="repeatexp"></A>
<P>In class <CODE>RepeatExpression</CODE>, the <CODE>accept:</CODE> method
sends the <CODE>visitRepeat:</CODE> message.
In class <CODE>AlternationExpression</CODE>, it sends the
<CODE>visitAlternation:</CODE> message.
In class <CODE>LiteralExpression</CODE>, it sends the
<CODE>visitLiteral:</CODE> message.</P>

<A NAME="seqexp"></A>
<P>The four classes also must have accessing functions that the visitor
can use.  For <CODE>SequenceExpression</CODE> these are
<CODE>expression1</CODE> and <CODE>expression2</CODE>; for
<CODE>AlternationExpression</CODE> these are <CODE>alternative1</CODE>
and <CODE>alternative2</CODE>; for
<CODE>RepeatExpression</CODE> it is <CODE>repetition</CODE>; and for
<CODE>LiteralExpression</CODE> these are <CODE>components</CODE>.</P>

<A NAME="auto1084"></A>
<P>The ConcreteVisitor class is <CODE>REMatchingVisitor</CODE>.  It
is responsible for the traversal because its traversal algorithm
is irregular.  The biggest irregularity is that a
<CODE>RepeatExpression</CODE> will repeatedly traverse its component.
The class <CODE>REMatchingVisitor</CODE> has an instance variable
<CODE>inputState</CODE>.   Its methods are essentially the same as
the <CODE>match:</CODE> methods of the expression classes in the
Interpreter pattern except they
replace the argument named <CODE>inputState</CODE> with the
expression node being matched.  However, they
still return the set of streams that the expression would match
to identify the current state.</P>

<A NAME="auto1085"></A>
<PRE>
    visitSequence: sequenceExp
        inputState := sequenceExp expression1 accept: self.
        ^ sequenceExp expression2 accept: self.
    
    visitRepeat: repeatExp
        | finalState |
        finalState := inputState copy.
        [inputState isEmpty]
            whileFalse:
                [inputState := repeatExp repetition accept: self.
                finalState addAll: inputState].
        ^ finalState
    
    visitAlternation: alternateExp
        | finalState originalState |
        originalState := inputState.
        finalState := alternateExp alternative1 accept: self.
        inputState := originalState.
        finalState addAll: (alternateExp alternative2 accept: self).
        ^ finalState
    
    visitLiteral: literalExp
        | finalState tStream |
        finalState := Set new.
        inputState
            do:
                [:stream | tStream := stream copy.
                    (tStream nextAvailable:
                        literalExp components size
                    ) = literalExp components
                        ifTrue: [finalState add: tStream]
                ].
        ^ finalState
</PRE>

<A NAME="knownuses"><A>
<H2><A HREF="#relatedpatterns"><IMG SRC="down3-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/gifsb/down3.gif" BORDER=0 
ALT="next: Related Patterns"></A> Known Uses</H2> 

<A NAME="smalltalk-use-visitor"></A>
<P>The Smalltalk-80 compiler has a Visitor class called ProgramNodeEnumerator.
It's used primarily for algorithms that analyze source code.
It isn't used for code generation or pretty-printing, although it could be.</P>

<A NAME="auto1086"></A>
<P>IRIS Inventor [<A HREF="bibfs-1.htm#strauss_oopsla93" tppabs="http://ultra/development/DesignPatterns/lowres/bibfs.htm#strauss_oopsla93" TARGET="_mainDisplayFrame">Str93</A>]
is a toolkit for developing 3-D graphics applications. Inventor
represents a three-dimensional scene as a hierarchy of nodes, each
representing either a geometric object or an attribute of one.
Operations like rendering a scene or mapping an input event require
traversing this hierarchy in different ways. Inventor does this
using visitors called "actions." There are different visitors for
rendering, event handling, searching, filing, and determining
bounding boxes.</P>

<A NAME="auto1087"></A>
<P>To make adding new nodes easier, Inventor implements a
double-dispatch scheme for C++. The scheme relies on run-time type
information and a two-dimensional table in which rows represent
visitors and columns represent node classes.  The cells store a
pointer to the function bound to the visitor and node class.</P>

<A NAME="fresco"></A>
<A NAME="linton"></A>
<P>Mark Linton coined the term "Visitor" in the X Consortium's
Fresco Application Toolkit specification [<A HREF="bibfs-1.htm#fresco" tppabs="http://ultra/development/DesignPatterns/lowres/bibfs.htm#fresco" TARGET="_mainDisplayFrame">LP93</A>].</P>

<A NAME="relatedpatterns"></A>
<H2><A HREF="#last"><IMG SRC="down3-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/gifsb/down3.gif" BORDER=0 ALT="next: 
navigation"></A> Related Patterns</H2> 

<A NAME="auto1088"></A>
<P><A HREF="pat4cfs-1.htm" tppabs="http://ultra/development/DesignPatterns/lowres/pat4cfs.htm" TARGET="_mainDisplayFrame">Composite (163)</A>:
Visitors can be used to apply an operation over an object structure
defined by the Composite pattern.</P>

<A NAME="auto1089"></A>
<P><A HREF="pat5cfs-1.htm" tppabs="http://ultra/development/DesignPatterns/lowres/pat5cfs.htm" TARGET="_mainDisplayFrame">Interpreter (243)</A>:
Visitor may be applied to do the interpretation.</P>

<A NAME="last"></A>
<P><A HREF="#intent"><IMG SRC="up3-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/gifsb/up3.gif" BORDER=0></A><BR>
<A HREF="disc5fs-1.htm" tppabs="http://ultra/development/DesignPatterns/lowres/disc5fs.htm" TARGET="_mainDisplayFrame"><IMG SRC="rightar3-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/gifsb/rightar3.gif"
        ALIGN=TOP BORDER=0></A> <A HREF="disc5fs-1.htm" tppabs="http://ultra/development/DesignPatterns/lowres/disc5fs.htm"
        TARGET="_mainDisplayFrame">Discussion of Behavioral Patterns</A><BR>
<A HREF="pat5jfs-1.htm" tppabs="http://ultra/development/DesignPatterns/lowres/pat5jfs.htm" TARGET="_mainDisplayFrame"><IMG SRC="leftarr3-1.gif" tppabs="http://ultra/development/DesignPatterns/lowres/gifsb/leftarr3.gif"
        ALIGN=TOP BORDER=0></A> <A HREF="pat5jfs-1.htm" tppabs="http://ultra/development/DesignPatterns/lowres/pat5jfs.htm"
        TARGET="_mainDisplayFrame">Template Method</A>
</P>

<HR>

<A NAME="footnote10"></A>
<P><SUP>10</SUP>We could use function overloading to give these operations
the same simple name, like <CODE>Visit</CODE>, since the operations are
already differentiated by the parameter they're passed.  There are
pros and cons to such overloading.  On the one hand, it reinforces the
fact that each operation involves the same analysis, albeit on a
different argument.  On the other hand, that might make what's going
on at the call site less obvious to someone reading the code.  It
really boils down to whether you believe function overloading is good
or not.
</P>

<A NAME="footnote11"></A>
<P><SUP>11</SUP>If we can have <EM>double</EM>-dispatch, then why not
<EM>triple</EM> or <EM>quadruple</EM>, or any other number?  Actually,
double-dispatch is just a special case of <STRONG>multiple
dispatch</STRONG>, in which the operation is chosen based on any number of
types.  (CLOS actually supports multiple dispatch.)  Languages that
support double- or multiple dispatch lessen the need for the
Visitor pattern.
</P>

</BODY>

</HTML>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本精品一区二区三区高清| 亚洲国产你懂的| 美脚の诱脚舐め脚责91| 欧美色综合天天久久综合精品| 国产欧美一区二区在线观看| 国产一区三区三区| 久久―日本道色综合久久| 日本不卡1234视频| 日韩欧美在线不卡| 日韩在线一区二区三区| 在线播放国产精品二区一二区四区 | 国产另类ts人妖一区二区| 国产亚洲综合性久久久影院| 欧美日韩一二三| 石原莉奈在线亚洲三区| 国产网站一区二区三区| 91久久精品一区二区三| 日本v片在线高清不卡在线观看| 久久久久久**毛片大全| 色综合久久久久网| 毛片av中文字幕一区二区| 国产精品色在线观看| 欧美偷拍一区二区| 韩国成人福利片在线播放| 1024国产精品| 日韩欧美国产成人一区二区| 不卡一区二区中文字幕| 日韩国产欧美视频| 中文字幕一区二区三区不卡| 欧美精品日韩一本| a亚洲天堂av| 蜜桃传媒麻豆第一区在线观看| 中文字幕欧美一| 精品福利在线导航| 欧美影院精品一区| 成人黄色av电影| 美女诱惑一区二区| 亚洲一区免费视频| 国产精品三级电影| 欧美大片免费久久精品三p| 99热精品国产| 国产曰批免费观看久久久| 亚洲午夜久久久久久久久电影院| 久久视频一区二区| 在线成人小视频| 在线观看不卡视频| 国产 日韩 欧美大片| 美女诱惑一区二区| 日韩主播视频在线| 一区二区三区四区不卡视频 | 在线播放中文字幕一区| 91美女精品福利| 国产成人精品www牛牛影视| 图片区小说区国产精品视频 | 亚洲午夜久久久久久久久电影院| 国产视频一区二区在线| 欧美一区二区三区啪啪| 欧美综合一区二区| 91亚洲精华国产精华精华液| 粉嫩av一区二区三区| 国产自产v一区二区三区c| 五月婷婷综合在线| 亚洲福利视频一区二区| 一区二区三区91| 亚洲精品久久久蜜桃| 亚洲人成网站色在线观看| 日本一区二区免费在线观看视频 | 日本不卡一区二区三区高清视频| 亚洲一区在线观看免费观看电影高清 | 国产精品一区二区你懂的| 久久成人免费电影| 久久成人麻豆午夜电影| 久久国产三级精品| 极品美女销魂一区二区三区免费| 蜜桃精品在线观看| 极品美女销魂一区二区三区| 国产在线精品一区二区| 国产精品一卡二卡| 国产黄色精品网站| a美女胸又www黄视频久久| 成人激情小说乱人伦| 成人av电影在线| 色婷婷精品大在线视频| 欧美午夜在线观看| 欧美疯狂做受xxxx富婆| 欧美一区二区三区白人| 2023国产精品视频| 国产精品麻豆久久久| 亚洲男女一区二区三区| 一区二区三区av电影| 日日摸夜夜添夜夜添精品视频| 奇米影视一区二区三区小说| 老司机精品视频线观看86| 国产成人精品亚洲日本在线桃色| 99re6这里只有精品视频在线观看| 91麻豆.com| 在线成人av影院| 久久久久久久久99精品| 亚洲少妇30p| 日本不卡视频在线观看| 国产一区二区在线观看免费| 成人av电影免费观看| 欧美日韩中文字幕一区二区| 日韩三级中文字幕| 国产精品污污网站在线观看 | 亚洲成av人片一区二区梦乃| 久草这里只有精品视频| 成人91在线观看| 欧美日韩卡一卡二| 久久精品人人做人人综合| 亚洲色图欧美偷拍| 老司机精品视频在线| 成人av在线资源网站| 欧美精品三级日韩久久| 国产日韩精品一区| 天堂va蜜桃一区二区三区| 国产二区国产一区在线观看| 欧美在线|欧美| 国产欧美一区二区精品忘忧草| 亚洲国产另类av| 丁香啪啪综合成人亚洲小说| 9191精品国产综合久久久久久| 欧美激情一区二区三区| 日韩专区欧美专区| 一本色道久久综合亚洲aⅴ蜜桃| 欧美一级国产精品| 亚洲欧美日韩国产综合| 国产在线精品免费| 欧美日韩激情一区二区三区| 日本一区二区免费在线| 男男视频亚洲欧美| 欧美中文字幕不卡| 中文一区二区完整视频在线观看 | 亚洲欧美欧美一区二区三区| 韩国女主播成人在线| 欧美日韩一区在线观看| 国产精品少妇自拍| 国产一区在线看| 91精品国产欧美一区二区18| 亚洲日本在线视频观看| 国产精品一二三区| 欧美大黄免费观看| 偷拍与自拍一区| 欧美在线观看18| 一区二区日韩av| 99久久er热在这里只有精品66| 亚洲精品在线三区| 奇米精品一区二区三区在线观看一 | 制服丝袜在线91| 亚洲综合色网站| 99视频在线精品| 国产欧美日韩精品a在线观看| 久久超碰97人人做人人爱| 欧美日本在线播放| 亚洲一区电影777| 色狠狠av一区二区三区| 亚洲三级免费电影| 91在线porny国产在线看| 国产精品午夜在线| 成人美女在线视频| 国产精品欧美一区喷水| jlzzjlzz国产精品久久| 国产精品美女www爽爽爽| 国产精品乡下勾搭老头1| 精品999久久久| 国产精品一区在线观看你懂的| 久久亚洲精品国产精品紫薇| 精品午夜一区二区三区在线观看| 欧美成人艳星乳罩| 国产剧情av麻豆香蕉精品| 中文字幕av免费专区久久| jlzzjlzz欧美大全| 亚洲精品日日夜夜| 欧美日韩精品电影| 麻豆国产欧美一区二区三区| 精品国产91亚洲一区二区三区婷婷| 久草这里只有精品视频| 久久久国产午夜精品| 成人av在线播放网址| 依依成人综合视频| 欧美麻豆精品久久久久久| 美日韩一区二区| 欧美极品少妇xxxxⅹ高跟鞋| 91免费看片在线观看| 亚洲午夜一区二区三区| 欧美一区二区三区视频免费 | 成人app软件下载大全免费| 成人免费小视频| 欧美日本一区二区三区四区| 蜜桃视频在线观看一区二区| 久久精品人人做人人综合| 91免费版在线| 日韩av一区二区三区四区| 久久久99精品免费观看不卡| 91麻豆.com| 久久丁香综合五月国产三级网站| 国产欧美一区视频| 欧美日韩一区二区三区高清| 久久激情五月婷婷| 亚洲特黄一级片|