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

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

?? pat4c.htm

?? java設計范式.rar
?? HTM
?? 第 1 頁 / 共 2 頁
字號:
    class Component {    public:        //...        virtual Composite* GetComposite() { return 0; }    };        class Composite : public Component {    public:        void Add(Component*);        // ...        virtual Composite* GetComposite() { return this; }    };        class Leaf : public Component {        // ...    };</PRE><A NAME="auto1064"></A><P><CODE>GetComposite</CODE> lets you query a component to see if it's acomposite.  You can perform <CODE>Add</CODE> and<CODE>Remove</CODE> safely on the composite it returns.</P><A NAME="auto1065"></A><PRE>    Composite* aComposite = new Composite;    Leaf* aLeaf = new Leaf;        Component* aComponent;    Composite* test;        aComponent = aComposite;    if (test = aComponent->GetComposite()) {        test->Add(new Leaf);    }        aComponent = aLeaf;        if (test = aComponent->GetComposite()) {        test->Add(new Leaf); // will not add leaf    }</PRE><A NAME="dynamic_cast"></A><P>Similar tests for a Composite can be done using the C++<CODE>dynamic_cast</CODE> construct.</P><A NAME="auto1066"></A><P>Of course, the problem here is that we don't treat all componentsuniformly.  We have to revert to testing for different types beforetaking the appropriate action.</P><A NAME="auto1067"></A><P>The only way to provide transparency is to define default<CODE>Add</CODE> and <CODE>Remove</CODE> operations in Component.  Thatcreates a new problem: There's no way to implement<CODE>Component::Add</CODE> without introducing the possibility of itfailing.  You could make it do nothing, but that ignores an importantconsideration; that is, an attempt to add something to a leaf probablyindicates a bug.  In that case, the <CODE>Add</CODE> operation producesgarbage.  You could make it delete its argument, but that might notbe what clients expect.</P><A NAME="auto1068"></A><P>Usually it's better to make <CODE>Add</CODE> and<CODE>Remove</CODE> fail by default (perhaps by raising anexception) if the component isn't allowed to have children or if theargument of <CODE>Remove</CODE> isn't a child of the component,respectively.</P><A NAME="auto1069"></A><P>Another alternative is to change the meaning of "remove" slightly.  Ifthe component maintains a parent reference, then we could redefine<CODE>Component::Remove</CODE> to remove itself from itsparent. However, there still isn't a meaningful interpretation for acorresponding <CODE>Add</CODE>.</P></LI><A NAME="auto1070"></A><P></P><A NAME="auto1071"></A><LI><EM>Should Component implement a list of Components?</EM>You might be tempted to define the set of children as an instancevariable in the Component class where the child access and managementoperations are declared.  But putting the child pointer in the baseclass incurs a space penalty for every leaf, even though a leaf neverhas children.  This is worthwhile only if there are relatively fewchildren in the structure.</LI><A NAME="auto1072"></A><P></P><A NAME="auto1073"></A><LI><EM>Child ordering.</EM>Many designs specify an ordering on the children of Composite. In theearlier Graphics example, ordering may reflect front-to-back ordering.If Composites represent parse trees, then compound statements can beinstances of a Composite whose children must be ordered to reflect theprogram.<A NAME="auto1074"></A><P>When child ordering is an issue, you must design child accessand management interfaces carefully to manage the sequence ofchildren.  The <A HREF="pat5dfs.htm" TARGET="_mainDisplayFrame">Iterator (257)</A> patterncan guide you in this.</P></LI><A NAME="auto1075"></A><P></P><A NAME="auto1076"></A><LI><EM>Caching to improve performance.</EM>If you need to traverse or search compositions frequently, theComposite class can cache traversal or search information about itschildren.  The Composite can cache actual results or just informationthat lets it short-circuit the traversal or search.  For example, thePicture class from the Motivation example could cache the bounding boxof its children.  During drawing or selection, this cached boundingbox lets the Picture avoid drawing or searching when its childrenaren't visible in the current window.<A NAME="auto1077"></A><P>Changes to a component will require invalidating the caches of itsparents.  This works best when components know their parents.  So ifyou're using caching, you need to define an interface for tellingcomposites that their caches are invalid.</P></LI><A NAME="auto1078"></A><P></P><A NAME="auto1079"></A><LI><EM>Who should delete components?</EM>In languages without garbage collection, it's usually best to make aComposite responsible for deleting its children when it's destroyed.An exception to this rule is when Leaf objects are immutable and thuscan be shared.</LI><A NAME="auto1080"></A><P></P><A NAME="auto1081"></A><LI><EM>What's the best data structure for storing components?</EM>Composites may use a variety of data structures to store theirchildren, including linked lists, trees, arrays, and hash tables.  Thechoice of data structure depends (as always) on efficiency.  In fact,it isn't even necessary to use a general-purpose data structure atall.  Sometimes composites have a variable for each child, although thisrequires each subclass of Composite to implement its own managementinterface.  See <A HREF="pat5cfs.htm" TARGET="_mainDisplayFrame">Interpreter (243)</A> for an example.</LI></OL><A NAME="samplecode"></A><H2><A HREF="#knownuses"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: Known Uses"></A> Sample Code</H2> <A NAME="auto1082"></A><P>Equipment such as computers and stereo components are often organizedinto part-whole or containment hierarchies. For example, a chassis cancontain drives and planar boards, a bus can contain cards, and acabinet can contain chassis, buses, and so forth. Such structures canbe modeled naturally with the Composite pattern.</P><A NAME="auto1083"></A><P><CODE>Equipment</CODE> class defines an interface for all equipment inthe part-whole hierarchy.</P><A NAME="auto1084"></A><PRE>    class Equipment {    public:        virtual ~Equipment();            const char* Name() { return _name; }            virtual Watt Power();        virtual Currency NetPrice();        virtual Currency DiscountPrice();            virtual void Add(Equipment*);        virtual void Remove(Equipment*);        virtual Iterator<Equipment*>* CreateIterator();    protected:        Equipment(const char*);    private:        const char* _name;    };</PRE><A NAME="auto1085"></A><P><CODE>Equipment</CODE> declares operations that return theattributes of a piece of equipment, like its power consumption andcost. Subclasses implement these operations for specific kinds ofequipment. <CODE>Equipment</CODE> also declares a<CODE>CreateIterator</CODE> operation that returns an <CODE>Iterator</CODE>(see <A HREF="chapCfs.htm" TARGET="_mainDisplayFrame">Appendix&nbsp;C</A>)for accessing its parts.  Thedefault implementation for this operation returns a NullIterator,which iterates over the empty set.</P><A NAME="auto1086"></A><P>Subclasses of <CODE>Equipment</CODE> might include Leaf classes thatrepresent disk drives, integrated circuits, and switches:</P><A NAME="auto1087"></A><PRE>    class FloppyDisk : public Equipment {    public:        FloppyDisk(const char*);        virtual ~FloppyDisk();            virtual Watt Power();        virtual Currency NetPrice();        virtual Currency DiscountPrice();    };</PRE><A NAME="auto1088"></A><P><CODE>CompositeEquipment</CODE> is the base class for equipmentthat contains other equipment. It's also a subclass of<CODE>Equipment</CODE>.</P><A NAME="auto1089"></A><PRE>    class CompositeEquipment : public Equipment {    public:        virtual ~CompositeEquipment();            virtual Watt Power();        virtual Currency NetPrice();        virtual Currency DiscountPrice();            virtual void Add(Equipment*);        virtual void Remove(Equipment*);        virtual Iterator<Equipment*>* CreateIterator();        protected:        CompositeEquipment(const char*);    private:        List<Equipment*> _equipment;    };</PRE><A NAME="auto1090"></A><P><CODE>CompositeEquipment</CODE> defines the operations for accessing andmanaging subequipment. The operations <CODE>Add</CODE> and<CODE>Remove</CODE> insert and delete equipment from the list of equipmentstored in the <CODE>_equipment</CODE> member.  The operation<CODE>CreateIterator</CODE> returns an iterator (specifically, aninstance of <CODE>ListIterator</CODE>) that will traverse this list.</P><A NAME="auto1091"></A><P>A default implementation of <CODE>NetPrice</CODE> might use<CODE>CreateIterator</CODE> to sum the net prices of thesubequipment<SUP><A NAME="fn2"></A><A HREF="#footnote2">2</A></SUP>:</P><A NAME="auto1092"></A><PRE>    Currency CompositeEquipment::NetPrice () {        Iterator<Equipment*>* i = CreateIterator();        Currency total = 0;            for (i->First(); !i->IsDone(); i->Next()) {            total += i->CurrentItem()->NetPrice();        }        delete i;        return total;    }</PRE><A NAME="auto1093"></A><P>Now we can represent a computer chassis as a subclass of<CODE>CompositeEquipment</CODE> called <CODE>Chassis</CODE>.<CODE>Chassis</CODE> inherits the child-related operations from<CODE>CompositeEquipment</CODE>.</P><A NAME="auto1094"></A><PRE>    class Chassis : public CompositeEquipment {    public:        Chassis(const char*);        virtual ~Chassis();            virtual Watt Power();        virtual Currency NetPrice();        virtual Currency DiscountPrice();    };</PRE><A NAME="auto1095"></A><P>We can define other equipment containers such as<CODE>Cabinet</CODE> and <CODE>Bus</CODE> in a similar way.That gives us everything we need to assemble equipment into a (prettysimple) personal computer:</P><A NAME="auto1096"></A><PRE>    Cabinet* cabinet = new Cabinet("PC Cabinet");    Chassis* chassis = new Chassis("PC Chassis");        cabinet->Add(chassis);        Bus* bus = new Bus("MCA Bus");    bus->Add(new Card("16Mbs Token Ring"));        chassis->Add(bus);    chassis->Add(new FloppyDisk("3.5in Floppy"));        cout &lt;&lt; "The net price is " &lt;&lt; chassis->NetPrice() &lt;&lt; endl;</PRE><A NAME="knownuses"></A><H2><A HREF="#relatedpatterns"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: Related Patterns"></A> Known Uses</H2> <A NAME="auto1097"></A><P>Examples of the Composite pattern can be found in almost allobject-oriented systems.  The original View class of SmalltalkModel/View/Controller [<A HREF="bibfs.htm#krasner_mvc" TARGET="_mainDisplayFrame">KP88</A>] was a Composite, and nearly every user interfacetoolkit or framework has followed in its steps, including ET++ (withits VObjects [<A HREF="bibfs.htm#et++" TARGET="_mainDisplayFrame">WGM88</A>]) and InterViews (Styles [<A HREF="bibfs.htm#InterViews3.1" TARGET="_mainDisplayFrame">LCI+92</A>],Graphics [<A HREF="bibfs.htm#interviews_graphic" TARGET="_mainDisplayFrame">VL88</A>], andGlyphs [<A HREF="bibfs.htm#interviews_glyphs" TARGET="_mainDisplayFrame">CL90</A>]).  It's interesting to note that theoriginal View of Model/View/Controller had a set of subviews; in other words, View wasboth the Component class and the Composite class.  Release 4.0 ofSmalltalk-80 revised Model/View/Controller with a VisualComponent class that hassubclasses View and CompositeView.</P><A NAME="rtlsmall-use-comp"></A><A NAME="ssa"></A><P>The RTL Smalltalk compiler framework [<A HREF="bibfs.htm#RTLSystem92" TARGET="_mainDisplayFrame">JML92</A>] uses theComposite pattern extensively.  RTLExpression is a Component class forparse trees. It has subclasses, such as BinaryExpression, that containchild RTLExpression objects.  These classes define a compositestructure for parse trees.  RegisterTransfer is the Component classfor a program's intermediate Single Static Assignment (SSA) form.Leaf subclasses of RegisterTransfer define different staticassignments such as</P><UL><A NAME="auto1098"></A><LI>primitive assignments that perform an operation on two registers andassign the result to a third;</LI><A NAME="auto1099"></A><P></P><A NAME="auto1100"></A><LI>an assignment with a source register but no destination register,which indicates that the register is used after a routine returns; and</LI><A NAME="auto1101"></A><P></P><A NAME="auto1102"></A><LI>an assignment with a destination register but no source, whichindicates that the register is assigned before the routine starts.</LI></UL><A NAME="auto1103"></A><P>Another subclass, RegisterTransferSet, is a Composite classfor representing assignments that change several registers at once.</P><A NAME="auto1104"></A><P>Another example of this pattern occurs in the financial domain, wherea portfolio aggregates individual assets.  You can support complexaggregations of assets by implementing a portfolio as a Composite thatconforms to the interface of an individualasset [<A HREF="bibfs.htm#birrer-egg_swaps" TARGET="_mainDisplayFrame">BE93</A>].</P><A NAME="auto1105"></A><P>The <A HREF="pat5bfs.htm" TARGET="_mainDisplayFrame">Command (233)</A> pattern describes how Command objectscan be composed and sequenced with a MacroCommand Composite class.</P><A NAME="relatedpatterns"></A><H2><A HREF="#last"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: navigation"></A> Related Patterns</H2> <A NAME="auto1106"></A><P>Often the component-parent link is used for a <A HREF="pat5afs.htm"TARGET="_mainDisplayFrame">Chain of Responsibility (223)</A>.</P><A NAME="compcomposite"></A><P><A HREF="pat4dfs.htm" TARGET="_mainDisplayFrame">Decorator (175)</A> isoften used with Composite.  When decorators and composites are usedtogether, they will usually have a common parent class.  So decoratorswill have to support the Component interface with operations likeAdd, Remove, and GetChild.</P><A NAME="auto1107"></A><P><A HREF="pat4ffs.htm" TARGET="_mainDisplayFrame">Flyweight (195)</A>lets you share components, but they can no longer refer to theirparents.</P><A NAME="auto1108"></A><P><A HREF="pat5dfs.htm" TARGET="_mainDisplayFrame">Iterator (257)</A> canbe used to traverse composites.</P><A NAME="auto1109"></A><P><A HREF="pat5kfs.htm" TARGET="_mainDisplayFrame">Visitor (331)</A>localizes operations and behavior that would otherwise be distributedacross Composite and Leaf classes.</P><A NAME="last"></A><P><A HREF="#intent"><IMG SRC="gifsb/up3.gif" BORDER=0></A><BR><A HREF="pat4dfs.htm" TARGET="_mainDisplayFrame"><IMG SRC="gifsb/rightar3.gif"	ALIGN=TOP BORDER=0></A> <A HREF="pat4dfs.htm"	TARGET="_mainDisplayFrame">Decorator</A><BR><A HREF="pat4bfs.htm" TARGET="_mainDisplayFrame"><IMG SRC="gifsb/leftarr3.gif"	ALIGN=TOP BORDER=0></A> <A HREF="pat4bfs.htm"	TARGET="_mainDisplayFrame">Bridge</A></P><HR><A NAME="footnote2"></A><P><SUP>2</SUP>It's easy to forget to deletethe iterator once you're done with it.  The Iterator pattern showshow to guard against such bugs on<A HREF="pat5dfs.htm#clean-up_proxy_for_iterators" TARGET="_mainDisplayFrame">page 266</A>.</P></BODY></HTML>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
粉嫩aⅴ一区二区三区四区 | 国产精品网站一区| 日韩精品一卡二卡三卡四卡无卡| 在线观看www91| 午夜欧美一区二区三区在线播放| 777午夜精品免费视频| 免费不卡在线视频| 2017欧美狠狠色| 国产成人免费视频网站 | 日韩精品专区在线影院观看| 乱中年女人伦av一区二区| 欧美精品一区在线观看| 国产成人亚洲精品青草天美| 亚洲日本在线看| 欧美日韩亚洲综合在线| 肉色丝袜一区二区| 久久久久久一二三区| 成人性生交大片免费看视频在线| 亚洲蜜臀av乱码久久精品| 欧美在线|欧美| 久草在线在线精品观看| 日本一区二区三区久久久久久久久不| 成a人片亚洲日本久久| 午夜影院在线观看欧美| 精品美女一区二区| 97se亚洲国产综合自在线不卡| 亚洲自拍偷拍av| 精品福利一区二区三区免费视频| 成人美女视频在线看| 亚洲午夜精品17c| 精品国产乱码久久久久久1区2区 | 91精品国产一区二区| 国产精品一区二区视频| 亚洲综合区在线| 久久影音资源网| 欧美日韩另类一区| 成人午夜电影久久影院| 五月天激情综合网| 成人欧美一区二区三区| 日韩一级欧美一级| 99精品偷自拍| 国内不卡的二区三区中文字幕| 一区二区三区免费观看| 国产性做久久久久久| 在线不卡一区二区| 91香蕉视频污| 国产在线播放一区| 视频一区视频二区在线观看| 国产精品欧美一级免费| 日韩欧美激情一区| 欧美三电影在线| 欧美三级韩国三级日本三斤| 国产白丝网站精品污在线入口| 天天亚洲美女在线视频| 亚洲人妖av一区二区| 国产日韩欧美一区二区三区乱码| 4438x亚洲最大成人网| 色哟哟在线观看一区二区三区| 久久99精品久久久久久久久久久久| 亚洲乱码国产乱码精品精小说 | 视频一区中文字幕国产| 亚洲同性gay激情无套| 国产日产欧产精品推荐色| 欧美一区二区三区播放老司机| 色8久久人人97超碰香蕉987| 丁香另类激情小说| 国产成人一区二区精品非洲| 激情综合色播五月| 日本不卡不码高清免费观看 | 日韩高清在线观看| 亚洲第一二三四区| 亚洲愉拍自拍另类高清精品| 亚洲猫色日本管| 亚洲精品成人悠悠色影视| 中文字幕制服丝袜成人av| 国产精品久久久久一区二区三区 | 亚洲日本在线看| **网站欧美大片在线观看| 国产三级精品视频| 中文字幕久久午夜不卡| 国产精品麻豆久久久| 男女男精品视频网| 国产伦理精品不卡| 亚洲日本在线看| 亚洲天堂网中文字| 亚洲色图视频网站| 亚洲日本中文字幕区| 亚洲精品乱码久久久久久日本蜜臀| 国产精品久久久久桃色tv| 最新国产成人在线观看| 亚洲一区二区三区在线播放| 午夜久久电影网| 美女一区二区三区| 国产精品一区二区久久精品爱涩| 成人少妇影院yyyy| 91麻豆福利精品推荐| 欧美怡红院视频| 日韩视频永久免费| 国产日韩欧美综合一区| 国产精品久久午夜夜伦鲁鲁| 亚洲天堂a在线| 一片黄亚洲嫩模| 人人精品人人爱| 国产美女精品人人做人人爽| 99在线视频精品| 欧美日韩免费在线视频| 精品粉嫩aⅴ一区二区三区四区| 国产亚洲婷婷免费| 欧美激情中文字幕一区二区| 亚洲一区二区在线播放相泽| 日本aⅴ亚洲精品中文乱码| 国产曰批免费观看久久久| 不卡一区二区三区四区| 欧美性三三影院| 久久先锋资源网| 最新日韩在线视频| 日本人妖一区二区| 成人av影视在线观看| 在线不卡a资源高清| 日本一区二区三区在线观看| 亚洲自拍另类综合| 久久se这里有精品| 99视频国产精品| 91精品国产综合久久福利软件| 久久久噜噜噜久噜久久综合| 亚洲午夜一二三区视频| 国产一区二区h| 欧美日韩中文国产| 国产精品丝袜一区| 蜜桃视频一区二区三区在线观看| 国产91色综合久久免费分享| 欧美日韩国产高清一区二区三区| 国产欧美一区在线| 免费看日韩精品| 一本一本大道香蕉久在线精品| 精品日韩成人av| 亚洲成国产人片在线观看| 国产·精品毛片| 日韩天堂在线观看| 亚洲综合视频在线| 波多野结衣中文字幕一区二区三区| 88在线观看91蜜桃国自产| 国产精品久线观看视频| 国产一区二区三区国产| 欧美日韩1区2区| 一区二区三区欧美久久| 成人黄色免费短视频| 欧美精品一区二区蜜臀亚洲| 亚洲.国产.中文慕字在线| 色欧美片视频在线观看| 中文在线一区二区| 久久99精品久久久| 91麻豆精品国产无毒不卡在线观看| 亚洲丝袜精品丝袜在线| 国产91高潮流白浆在线麻豆| 精品国产一二三| 久久国产视频网| 精品欧美乱码久久久久久1区2区| 视频一区二区国产| 欧洲一区在线电影| 亚洲精品日韩专区silk | 国产福利一区在线观看| 精品日韩欧美一区二区| 麻豆91在线播放| 日韩美女一区二区三区四区| 青青草精品视频| 日韩一级黄色片| 日本va欧美va欧美va精品| 欧美一区二区在线看| 男人操女人的视频在线观看欧美| 欧美精品1区2区3区| 日韩电影一区二区三区四区| 欧美一级在线观看| 麻豆精品新av中文字幕| 欧美一级二级三级乱码| 免费视频一区二区| 2017欧美狠狠色| 高清av一区二区| 国产精品久久久久久久午夜片| 成人中文字幕电影| 中文字幕视频一区二区三区久| www.欧美.com| 亚洲精品乱码久久久久久| 日本高清成人免费播放| 亚洲国产一区在线观看| 欧美一区二区三区在线看| 久久99精品久久久| 欧美国产国产综合| 色一区在线观看| 亚洲国产视频a| 欧美一二三在线| 懂色av一区二区三区免费看| 亚洲欧美日韩一区| 欧美日韩不卡一区二区| 激情文学综合网| 亚洲婷婷在线视频| 91精品婷婷国产综合久久竹菊| 激情都市一区二区| 中文字幕成人av| 欧美视频在线一区二区三区|