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

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

?? chap3-0.htm

?? Design Pattern 設計模式
?? 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一区二区三区免费野_久草精品视频
国产三级欧美三级日产三级99| 亚洲成人tv网| 日日夜夜精品免费视频| 国产一区二区免费在线| 在线精品视频一区二区| 国产欧美视频一区二区| 婷婷夜色潮精品综合在线| 成人黄色综合网站| 精品999久久久| 日本中文字幕不卡| 欧洲国内综合视频| 国产精品色哟哟| 国内精品伊人久久久久影院对白| 在线观看成人免费视频| 欧美激情在线一区二区| 久久精品国产秦先生| 欧美三级资源在线| 最新久久zyz资源站| 成人网页在线观看| 国产喷白浆一区二区三区| 久久福利视频一区二区| 欧美夫妻性生活| 麻豆91精品视频| 5月丁香婷婷综合| 亚洲一区二区三区在线看| 99国产精品国产精品久久| 日本一区二区免费在线| 国产揄拍国内精品对白| 欧美mv日韩mv亚洲| 精品在线观看视频| 欧美大片国产精品| 美女精品自拍一二三四| 91精品国产综合久久福利| 性做久久久久久免费观看欧美| 91国在线观看| 亚洲mv在线观看| 欧美裸体bbwbbwbbw| 日本视频一区二区三区| 欧美一卡2卡3卡4卡| 美腿丝袜亚洲色图| 精品少妇一区二区三区| 免费观看91视频大全| 日韩一区二区三区四区五区六区| 丝袜美腿成人在线| 91.com视频| 亚洲欧美日韩久久| 日韩欧美亚洲另类制服综合在线| 9人人澡人人爽人人精品| 日本亚洲电影天堂| 一区二区三区久久久| 国产精品美女视频| 久久久精品tv| 欧美tickling挠脚心丨vk| 欧美日韩一区二区在线观看| 欧美性生活一区| 波多野结衣精品在线| 九九视频精品免费| 奇米精品一区二区三区在线观看| 国产精品色在线观看| 国产亚洲精品久| 亚洲精品一区二区精华| 日韩欧美一区二区在线视频| 欧美视频在线播放| 在线区一区二视频| 色综合久久综合中文综合网| 成人午夜又粗又硬又大| 久久99深爱久久99精品| 蜜乳av一区二区三区| 视频一区二区国产| 午夜欧美视频在线观看| 一区二区三区不卡在线观看 | 久久99国产乱子伦精品免费| 石原莉奈一区二区三区在线观看| 一区二区三区精品视频| 亚洲丝袜美腿综合| 亚洲欧美日韩国产综合在线| 综合久久综合久久| 综合久久一区二区三区| 中文字幕一区二区三| 国产精品第13页| 专区另类欧美日韩| 亚洲靠逼com| 亚洲激情图片一区| 亚洲制服丝袜一区| 一区二区免费视频| 性做久久久久久久久| 偷拍与自拍一区| 日韩av一级片| 久久99热这里只有精品| 精品一区二区三区日韩| 久久97超碰色| 欧美日韩在线播放一区| 欧美日韩国产一级片| 欧美日韩色综合| 欧美日韩中文字幕精品| 91精品国产美女浴室洗澡无遮挡| 日韩一级大片在线观看| www成人在线观看| 中文字幕国产一区| 亚洲男人都懂的| 亚洲国产日韩a在线播放| 午夜av一区二区三区| 九九九久久久精品| 国产69精品久久777的优势| 91在线精品一区二区| 欧美久久久久久久久中文字幕| 日韩视频在线永久播放| 2023国产精华国产精品| 欧美国产乱子伦| 夜夜精品浪潮av一区二区三区| 婷婷开心激情综合| 国产精品综合视频| 日本精品一区二区三区高清 | 国产精品嫩草影院av蜜臀| 亚洲免费观看高清完整版在线 | 91麻豆成人久久精品二区三区| 色94色欧美sute亚洲线路一久| 欧美精品久久一区| 久久亚洲二区三区| 亚洲最大的成人av| 国产原创一区二区三区| 在线精品视频免费播放| 久久蜜桃香蕉精品一区二区三区| 一区二区三区四区激情| 久久99久国产精品黄毛片色诱| av电影一区二区| 日韩一级二级三级精品视频| 最新久久zyz资源站| 久久国产剧场电影| 一本到高清视频免费精品| 精品日韩99亚洲| 亚洲综合丁香婷婷六月香| 国产一区二区伦理片| 91福利视频在线| 国产日韩欧美一区二区三区乱码 | 国产精品三级在线观看| 免费三级欧美电影| 色综合久久综合网| 久久久亚洲高清| 天天色天天操综合| 91捆绑美女网站| 久久免费视频一区| 免费成人在线影院| 欧美午夜不卡在线观看免费| 欧美国产禁国产网站cc| 精品一区二区三区在线播放视频| 欧美视频一区二区三区四区| 国产精品久久久久久亚洲伦| 国内不卡的二区三区中文字幕| 欧美日韩精品系列| 亚洲欧美偷拍卡通变态| 国产成人欧美日韩在线电影| 91精品国产综合久久香蕉麻豆| 青椒成人免费视频| 欧美日韩夫妻久久| 亚洲午夜在线视频| 在线视频欧美区| 亚洲三级在线看| 不卡的av电影在线观看| 国产日产欧产精品推荐色| 久久国产精品一区二区| 日韩精品在线一区二区| 久久99精品久久久| 日韩欧美久久一区| 美女视频一区在线观看| 在线综合视频播放| 日韩av一级电影| 日韩一级成人av| 美女视频黄频大全不卡视频在线播放| 欧美日韩亚洲综合| 亚洲www啪成人一区二区麻豆 | 欧美精品高清视频| 五月天一区二区| 欧美人狂配大交3d怪物一区| 午夜影院在线观看欧美| 欧美日韩在线播放| 五月天丁香久久| 日韩一级在线观看| 国产一区二区三区四| 国产欧美综合在线| av一区二区三区在线| 亚洲激情一二三区| 欧美久久久久中文字幕| 男男视频亚洲欧美| 国产三级一区二区| 92国产精品观看| 亚洲高清视频在线| 欧美一二三四在线| 国产一区二区三区四| 欧美国产精品一区| 色婷婷国产精品久久包臀| 午夜视频一区二区| 日韩欧美国产三级| 粉嫩嫩av羞羞动漫久久久 | 亚洲一区免费在线观看| 欧美日韩电影在线播放| 久久国产生活片100| 欧美国产精品一区二区三区| 色av成人天堂桃色av| 秋霞av亚洲一区二区三|