Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet103/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   99   100   101   102   103   104   105   106   ...   288
Bog'liq
GOF Design Patterns
Копасов Игорь (1), Т Е Л Е Ф О Н О Г Р А М М А ЗООМ, 20201546 п.80 использ., Oliy matematika, презентация индустрия мутакил иши, 3000 most common words in English, Sun'iy intellekt, 1638511850 AE, 1638511850 AE, Hisob-raqan (Patent boji), O'RQ-600 23-MODDA, Talabaning haftalik hisoboti namunasi , iikinchi hafta amaliyoti., Таҳлил тест
Design Patterns: Elements of Reusable Object-Oriented Software 
139 
MazePrototypeFactory(Maze*, Wall*, Room*, Door*); 
virtual Maze* MakeMaze() const; 
virtual Room* MakeRoom(int) const; 
virtual Wall* MakeWall() const; 
virtual Door* MakeDoor(Room*, Room*) const; 
private: 
Maze* _prototypeMaze; 
Room* _prototypeRoom; 
Wall* _prototypeWall; 
Door* _prototypeDoor; 
}; 
The new constructor simply initializes its prototypes: 
MazePrototypeFactory::MazePrototypeFactory ( 
Maze* m, Wall* w, Room* r, Door* d 
) { 
_prototypeMaze = m; 
_prototypeWall = w; 
_prototypeRoom = r; 
_prototypeDoor = d; 

The member functions for creating walls, rooms, and doors are similar: Each clones 
a prototype and then initializes it. Here are the definitions of MakeWall and 
MakeDoor: 
Wall* MazePrototypeFactory::MakeWall () const { 
return _prototypeWall->Clone(); 

Door* MazePrototypeFactory::MakeDoor (Room* r1, Room *r2) const { 
Door* door = _prototypeDoor->Clone(); 
door->Initialize(r1, r2); 
return door; 

We can use MazePrototypeFactory to create a prototypical or default maze just 
by initializing it with prototypes of basic maze components:


Design Patterns: Elements of Reusable Object-Oriented Software 
140 
MazeGame game; 
MazePrototypeFactory simpleMazeFactory( 
new Maze, new Wall, new Room, new Door 
); 
Maze* maze = game.CreateMaze(simpleMazeFactory); 
To change the type of maze, we initialize MazePrototypeFactory with a different 
set of prototypes. The following call creates a maze with a BombedDoor and a 
RoomWithABomb: 
MazePrototypeFactory bombedMazeFactory( 
new Maze, new BombedWall, 
new RoomWithABomb, new Door 
); 
An object that can be used as a prototype, such as an instance of Wall, must support 
the Clone operation. It must also have a copy constructor for cloning. It may 
also need a separate operation for reinitializing internal state. We'll add the 
Initialize operation to Door to let clients initialize the clone's rooms. 
Compare the following definition of Door to the one on page 96:
class Door : public MapSite { 
public: 
Door(); 
Door(const Door&); 
virtual void Initialize(Room*, Room*); 
virtual Door* Clone() const; 
virtual void Enter(); 
Room* OtherSideFrom(Room*); 
private: 
Room* _room1; 
Room* _room2; 
}; 
Door::Door (const Door& other) { 
_room1 = other._room1; 
_room2 = other._room2; 




Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   99   100   101   102   103   104   105   106   ...   288




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2022
ma'muriyatiga murojaat qiling

    Bosh sahifa
davlat universiteti
ta’lim vazirligi
axborot texnologiyalari
maxsus ta’lim
zbekiston respublikasi
guruh talabasi
O’zbekiston respublikasi
nomidagi toshkent
o’rta maxsus
davlat pedagogika
texnologiyalari universiteti
toshkent axborot
xorazmiy nomidagi
rivojlantirish vazirligi
pedagogika instituti
Ўзбекистон республикаси
tashkil etish
haqida tushuncha
таълим вазирлиги
vazirligi muhammad
O'zbekiston respublikasi
toshkent davlat
махсус таълим
respublikasi axborot
kommunikatsiyalarini rivojlantirish
vazirligi toshkent
saqlash vazirligi
fanidan tayyorlagan
bilan ishlash
Toshkent davlat
sog'liqni saqlash
uzbekistan coronavirus
respublikasi sog'liqni
coronavirus covid
koronavirus covid
vazirligi koronavirus
qarshi emlanganlik
covid vaccination
risida sertifikat
sertifikat ministry
vaccination certificate
Ishdan maqsad
fanidan mustaqil
matematika fakulteti
o’rta ta’lim
haqida umumiy
fanlar fakulteti
pedagogika universiteti
ishlab chiqarish
moliya instituti
fanining predmeti