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

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

?? chap3-0.htm

?? java設計范式.rar
?? HTM
字號:
<HTML><HEAD><TITLE>Creational Patterns</TITLE><SCRIPT>function setFocus() {		if ((navigator.appName != "Netscape") && (parseFloat(navigator.appVersion) == 2)) {	return;	} else {	self.focus();	}}</SCRIPT></HEAD><BODY BGCOLOR	= #FFFFFF      TEXT = #000000onLoad="setFocus()";><A NAME="top"></A><A NAME="creation_top1"></A><P>Creational design patterns abstract the instantiation process.They help make a system independent of how its objects are created,composed, and represented. A class creational pattern uses inheritanceto vary the class that's instantiated, whereas an object creationalpattern will delegate instantiation to another object.<A NAME="creation_top2"></A><P>Creational patterns become important as systems evolve to depend moreon object composition than class inheritance. As that happens,emphasis shifts away from hard-coding a fixed set of behaviors towarddefining a smaller set of fundamental behaviors that can be composedinto any number of more complex ones. Thus creating objects withparticular behaviors requires more than simply instantiating a class.<A NAME="creation_top2"></A><P>There are two recurring themes in these patterns. First, they allencapsulate knowledge about which concrete classes the system uses.Second, they hide how instances of these classes are created and puttogether. All the system at large knows about the objects is theirinterfaces as defined by abstract classes. Consequently, thecreational patterns give you a lot of flexibility in <EM>what</EM> getscreated, <EM>who</EM> creates it, <EM>how</EM> it gets created, and <EM>when</EM>. They let you configure a system with "product" objects thatvary widely in structure and functionality.  Configuration can bestatic (that is, specified at compile-time) or dynamic (atrun-time).<A NAME="creation_top3"></A><P>Sometimes creational patterns are competitors. For example,there are cases when either <A HREF="pat3dfs.htm" TARGET="_mainDisplayFrame">Prototype (117)</A>or <A HREF="pat3afs.htm" TARGET="_mainDisplayFrame">Abstract Factory (87)</A> couldbe used profitably. At other times they are complementary:<A HREF="pat3bfs.htm" TARGET="_mainDisplayFrame">Builder (97)</A> can use one of the otherpatterns to implement which components get built.<A HREF="pat3dfs.htm" TARGET="_mainDisplayFrame">Prototype (117)</A> can use<A HREF="pat3efs.htm" TARGET="_mainDisplayFrame">Singleton (127)</A> in its implementation.<A NAME="creation_top4"></A><P>Because the creational patterns are closely related, we'll study allfive of them together to highlight their similarities and differences.We'll also use a common example&#151;building a maze for a computergame&#151;to illustrate their implementations. The maze and the game willvary slightly from pattern to pattern. Sometimes the game will besimply to find your way out of a maze; in that case the player willprobably only have a local view of the maze. Sometimes mazes containproblems to solve and dangers to overcome, and these games may providea map of the part of the maze that has been explored.<A NAME="creation_top5"></A><P>We'll ignore many details of what can be in a maze and whether a mazegame has a single or multiple players. Instead, we'll just focus onhow mazes get created. We define a maze as a set of rooms. A roomknows its neighbors; possible neighbors are another room, a wall, or adoor to another room.<A NAME="creation_top6"></A><P>The classes <CODE>Room</CODE>, <CODE>Door</CODE>, and <CODE>Wall</CODE>define the components of the maze used in all our examples. We defineonly the parts of these classes that are important for creating amaze.  We'll ignore players, operations for displaying and wanderingaround in a maze, and other important functionality that isn'trelevant to building the maze.<P>The following diagram shows the relationships between these classes:<A NAME="room-82c"></A><P ALIGN=CENTER><IMG SRC="Pictures/maze.gif"></P><P>Each room has four sides. We use an enumeration <CODE>Direction</CODE> inC++ implementations to specify the north, south, east, and west sides ofa room:</P><PRE>    enum Direction {North, South, East, West};</PRE><P>The Smalltalk implementations use corresponding symbols to representthese directions.</P><A NAME="mapsite"></A><P>The class <CODE>MapSite</CODE> is the common abstract class for all thecomponents of a maze. To simplify the example, <CODE>MapSite</CODE> definesonly one operation, <CODE>Enter</CODE>. Its meaning depends on what you'reentering. If you enter a room, then your location changes. If you try toenter a door, then one of two things happen: If the door is open, you gointo the next room. If the door is closed, then you hurt your nose.</P><PRE>    class MapSite {    public:        virtual void Enter() = 0;    };</PRE><A NAME="mapsite2"></A><P><CODE>Enter</CODE> provides a simple basis for more sophisticated gameoperations. For example, if you are in a room and say "Go East," thegame can simply determine which <CODE>MapSite</CODE> is immediately to theeast and then call <CODE>Enter</CODE> on it. The subclass-specific<CODE>Enter</CODE> operation will figure out whether your location changedor your nose got hurt. In a real game, <CODE>Enter</CODE> could take theplayer object that's moving about as an argument.</P><A NAME="def-room"></A><P><CODE>Room</CODE> is the concrete subclass of <CODE>MapSite</CODE> thatdefines the key relationships between components in the maze. Itmaintains references to other <CODE>MapSite</CODE> objects and stores aroom number. The number will identify rooms in the maze.</P><PRE>    class Room : public MapSite {    public:        Room(int roomNo);            MapSite* GetSide(Direction) const;        void SetSide(Direction, MapSite*);            virtual void Enter();        private:        MapSite* _sides[4];        int _roomNumber;    };</PRE><A NAME="wall-code"></A><A NAME="door-code"></A><P>The following classes represent the wall or door that occurs on eachside of a room.</P><PRE>    class Wall : public MapSite {    public:        Wall();            virtual void Enter();    };        class Door : public MapSite {    public:        Door(Room* = 0, Room* = 0);            virtual void Enter();        Room* OtherSideFrom(Room*);        private:        Room* _room1;        Room* _room2;        bool _isOpen;    };</PRE><A NAME="Door-def"></A><A NAME="maze-def"></A><P>We need to know about more than just the parts of a maze. We'll alsodefine a <CODE>Maze</CODE> class to represent a collection of rooms.<CODE>Maze</CODE> can also find a particular room given a room numberusing its <CODE>RoomNo</CODE> operation.</P><PRE>    class Maze {    public:        Maze();            void AddRoom(Room*);        Room* RoomNo(int) const;    private:        // ...    };</PRE><P><CODE>RoomNo</CODE> could do a look-up using a linear search, a hash table,or even a simple array. But we won't worry about such details here.Instead, we'll focus on how to specify the components of a maze object.</P><A NAME="mazegame"></A><P>Another class we define is <CODE>MazeGame</CODE>, which creates the maze.One straightforward way to create a maze is with a series of operationsthat add components to a maze and then interconnect them.  Forexample, the following member function will create a maze consistingof two rooms with a door between them:</P><A NAME="CreateMaze-def"></A><PRE>    Maze* MazeGame::CreateMaze () {        Maze* aMaze = new Maze;        Room* r1 = new Room(1);        Room* r2 = new Room(2);        Door* theDoor = new Door(r1, r2);            aMaze->AddRoom(r1);        aMaze->AddRoom(r2);            r1->SetSide(North, new Wall);        r1->SetSide(East, theDoor);        r1->SetSide(South, new Wall);        r1->SetSide(West, new Wall);            r2->SetSide(North, new Wall);        r2->SetSide(East, new Wall);        r2->SetSide(South, new Wall);        r2->SetSide(West, theDoor);            return aMaze;    }</PRE><A NAME="CreateMaze-text1"></A><P>This function is pretty complicated, considering that all it does is createa maze with two rooms. There are obvious ways to make it simpler. Forexample, the <CODE>Room</CODE> constructor could initialize the sideswith walls ahead of time. But that just moves the code somewhere else.The real problem with this member function isn't its size but its <EM>inflexibility</EM>. It hard-codes the maze layout. Changing the layoutmeans changing this member function, either by overriding it&#151;whichmeans reimplementing the whole thing&#151;or by changing parts ofit&#151;which is error-prone and doesn't promote reuse.</P><A NAME="CreateMaze-text2"></A><P>The creational patterns show how to make this design more <EM>flexible</EM>, not necessarily smaller. In particular, they will make iteasy to change the classes that define the components of a maze.</P><A NAME="CreateMaze-text2"></A><P>Suppose you wanted to reuse an existing maze layout for a new gamecontaining (of all things) enchanted mazes. The enchanted maze game hasnew kinds of components, like <CODE>DoorNeedingSpell</CODE>, a door thatcan be locked and opened subsequently only with a spell; and<CODE>EnchantedRoom</CODE>, a room that can have unconventional items init, like magic keys or spells. How can you change <CODE>CreateMaze</CODE>easily so that it creates mazes with these new classes of objects?</P><A NAME="CreateMaze-text3"></A><P>In this case, the biggest barrier to change lies in hard-coding theclasses that get instantiated. The creational patterns providedifferent ways to remove explicit references to concrete classesfrom code that needs to instantiate them:</P><UL><A NAME="CreateMaze-text4"></A><LI>If <CODE>CreateMaze</CODE> calls virtual functions instead of constructorcalls to create the rooms, walls, and doors it requires, then you canchange the classes that get instantiated by making a subclass of<CODE>MazeGame</CODE> and redefining those virtual functions. This approachis an example of the<A HREF="pat3cfs.htm" TARGET="_mainDisplayFrame">Factory Method (107)</A> pattern.</LI><P></P><A NAME="CreateMaze-text5"></A><LI>If <CODE>CreateMaze</CODE> is passed an object as a parameter to use tocreate rooms, walls, and doors, then you can change the classes ofrooms, walls, and doors by passing a different parameter. This is anexample of the <A HREF="pat3afs.htm" TARGET="_mainDisplayFrame">Abstract Factory (87)</A> pattern.</LI><P></P><A NAME="CreateMaze-text6"></A><LI>If <CODE>CreateMaze</CODE> is passed an object that can create a new mazein its entirety using operations for adding rooms, doors, and walls tothe maze it builds, then you can use inheritance to change parts ofthe maze or the way the maze is built. This is an example of the<A HREF="pat3bfs.htm" TARGET="_mainDisplayFrame">Builder (97)</A> pattern.</LI><P></P><A NAME="CreateMaze-text7"></A><LI>If <CODE>CreateMaze</CODE> is parameterized by various prototypical room,door, and wall objects, which it then copies and adds to the maze,then you can change the maze's composition by replacing theseprototypical objects with different ones. This is an example of the<A HREF="pat3dfs.htm" TARGET="_mainDisplayFrame">Prototype (117)</A> pattern.</LI></UL><A NAME="CreateMaze-text8"></A><P>The remaining creational pattern, <A HREF="pat3efs.htm"TARGET="_mainDisplayFrame">Singleton (127)</A>, canensure there's only one maze per game and that all game objects haveready access to it&#151;without resorting to global variables orfunctions.  Singleton also makes it easy to extend or replace the mazewithout touching existing code.</P><A NAME="last"></A><P><A HREF="#top"><IMG SRC="gifsb/up3.gif" BORDER=0></A><BR><A HREF="pat3afs.htm" TARGET="_mainDisplayFrame"><IMG SRC="gifsb/rightar3.gif"	ALIGN=TOP BORDER=0></A> <A HREF="pat3afs.htm"	TARGET="_mainDisplayFrame">Abstract Factory</A><BR><A HREF="patcafs.htm" TARGET="_mainDisplayFrame"><IMG SRC="gifsb/leftarr3.gif"	ALIGN=TOP BORDER=0></A> <A HREF="patcafs.htm"	TARGET="_mainDisplayFrame">Pattern Catalog</A></P></BODY></HTML>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美在线不卡视频| 亚洲欧美另类综合偷拍| youjizz国产精品| 亚洲成人黄色影院| 精品国产成人系列| 国产不卡在线一区| 亚洲成av人片一区二区| 国产精品网曝门| aaa国产一区| 久久99久久精品| 亚洲精选视频免费看| 欧美精品一区二区三区蜜臀| 一本色道久久综合狠狠躁的推荐| 免费观看一级特黄欧美大片| 日本一区二区视频在线| 欧美高清视频一二三区| 成人一级片网址| 青娱乐精品视频在线| 欧美日韩成人综合天天影院| 极品美女销魂一区二区三区免费| 一区二区在线观看视频| 久久影院视频免费| 成人免费毛片片v| 日韩精品一二区| 精品国产91洋老外米糕| 欧美午夜电影一区| av在线不卡免费看| 国产精品88888| 琪琪一区二区三区| 亚洲制服丝袜一区| 国产精品动漫网站| 久久精品一区八戒影视| 中文字幕一区二区三区精华液 | 欧美一区二区播放| 欧美日韩一卡二卡三卡| 91电影在线观看| 91老司机福利 在线| 97精品视频在线观看自产线路二| 欧美精品一二三| 在线成人午夜影院| 色香蕉久久蜜桃| 色综合久久中文综合久久牛| 成人av在线观| av中文字幕亚洲| 99久久综合精品| 91精品一区二区三区在线观看| 欧美日韩一区国产| 在线91免费看| 欧美成人a视频| 日韩免费看的电影| 26uuu精品一区二区| 国产偷国产偷精品高清尤物| 国产精品视频看| 国产精品电影院| 一区二区三区成人| 香港成人在线视频| 久久99精品久久久久久国产越南| 国产麻豆精品在线| 99在线精品观看| 欧美三区在线观看| 精品欧美一区二区在线观看| 久久亚洲精品小早川怜子| 国产日韩欧美一区二区三区综合 | 欧美日免费三级在线| 欧美日韩国产乱码电影| 精品日韩在线观看| 欧美激情中文字幕| 亚洲已满18点击进入久久| 亚洲福利一区二区三区| 麻豆精品视频在线| 播五月开心婷婷综合| www.亚洲免费av| 欧美丰满嫩嫩电影| wwwwxxxxx欧美| 中文字幕av一区二区三区高 | 96av麻豆蜜桃一区二区| 色美美综合视频| 欧美一区二区三区人| 欧美激情在线看| 一区二区三区日本| 久久国产免费看| 成人av在线电影| 91精品国产欧美一区二区18| 欧美韩国日本不卡| 亚洲黄色小说网站| 老司机午夜精品| eeuss国产一区二区三区| 欧美伦理影视网| 国产日韩精品一区二区三区 | 久久在线免费观看| 亚洲一级不卡视频| 大白屁股一区二区视频| 欧美日韩亚洲高清一区二区| 国产亚洲精品久| 午夜激情一区二区三区| 成人一区二区三区视频| 欧美成人官网二区| 亚洲老司机在线| 国产成人免费视频网站| 欧美人伦禁忌dvd放荡欲情| 国产免费成人在线视频| 日本欧美一区二区三区| 91免费观看视频| 国产性色一区二区| 免费亚洲电影在线| 欧美做爰猛烈大尺度电影无法无天| 久久婷婷色综合| 日本伊人色综合网| 精品视频免费看| 国产精品福利影院| 国产精品77777| 日韩精品专区在线影院重磅| 亚洲观看高清完整版在线观看| 国产成人av电影在线观看| 日韩女优制服丝袜电影| 亚洲va中文字幕| 精品视频在线视频| 亚洲欧洲另类国产综合| 国产成人精品三级| 欧美xingq一区二区| 奇米777欧美一区二区| 欧美日韩一区二区欧美激情 | 国产精品第四页| 国产麻豆9l精品三级站| 日韩免费高清av| 日本成人在线一区| 欧美久久久久久久久中文字幕| 尤物视频一区二区| 99精品视频在线免费观看| 欧美国产一区二区| 国产成人av资源| 国产亚洲一区二区三区在线观看| 国产在线播放一区| 精品国产百合女同互慰| 韩国成人福利片在线播放| 337p粉嫩大胆色噜噜噜噜亚洲| 亚洲在线免费播放| 99久久久国产精品| 亚洲三级在线观看| 色婷婷国产精品综合在线观看| 亚洲视频狠狠干| 欧美影视一区在线| 婷婷丁香激情综合| 欧美一级二级三级乱码| 日韩二区三区四区| 欧美sm极限捆绑bd| 国产精品自拍三区| 亚洲国产成人在线| 99国产精品久久久| 亚洲福利一二三区| 日韩女优av电影在线观看| 精品影视av免费| 中文字幕不卡在线观看| www.日韩精品| 有坂深雪av一区二区精品| 欧美性一级生活| 蜜桃传媒麻豆第一区在线观看| 久久影院午夜片一区| 国产精品夜夜爽| 中文字幕亚洲在| 91久久线看在观草草青青| 一区二区三区四区乱视频| 欧美日本在线一区| 国产一区二区网址| 欧美日本在线看| 国产精品婷婷午夜在线观看| 欧洲亚洲国产日韩| 蜜臀精品一区二区三区在线观看| 久久综合九色综合97婷婷女人| www..com久久爱| 亚洲国产精品视频| 精品精品欲导航| 色综合久久综合网97色综合| 三级久久三级久久久| 久久久久久黄色| 91黄色免费看| 久久电影国产免费久久电影| 国产精品夫妻自拍| 欧美精品色综合| 成人黄色网址在线观看| 日本少妇一区二区| 国产精品国产成人国产三级| 欧美一区二区在线免费观看| 国产69精品久久久久毛片| 亚洲综合在线五月| 欧美精品一区二区三区很污很色的 | 久久综合网色—综合色88| 蜜桃久久久久久| 成人免费在线视频观看| 欧美日韩成人在线一区| 国产激情91久久精品导航| 亚洲女厕所小便bbb| 欧美在线免费观看亚洲| 国产一区二区三区免费在线观看| 国产视频在线观看一区二区三区 | 国产精品99久久久久久似苏梦涵| 一二三四社区欧美黄| 久久久不卡影院| 欧美美女一区二区三区| 91免费小视频|