top of page

Паттерн "Абстрактная фабрика"

Объекты-владельцы

// Test01.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include <iostream>

struct Wall {};

struct Room { Room(int n) {} };

struct Door { Door(Room* r1, Room* r2) {} };

struct Maze

{

void AddRoom(Room* const pRoom) {}

};

class MazeFactory

{

public:

MazeFactory() {}

virtual Maze* MakeMaze() const

{ return new Maze; }

virtual Wall* MakeWall() const

{ return new Wall; }

virtual Room* MakeRoom(int n) const

{ return new Room(n); }

virtual Door* MakeDoor(Room* r1, Room* r2) const

{ return new Door(r1, r2); }

};

struct MazeGame

{

Maze* CreateMaze(MazeFactory& factory);

};

 

int _tmain(int argc, _TCHAR* argv[])

{

::getchar();

return 0;

}

bottom of page