: C10:AbstractFactory.cpp // И
Автор admin
Суббота, 20 июня 2009 11:32
: C10:AbstractFactory.cpp // Игровая среда, linclude using namespace std: class Obstacle { public: virtual void actionО = 0: }: class Player { public: virtual void interactWithCObstacle*) = 0: }: class Kitty: public Player { virtual void interactWith(Obstacle* ob) { cout « “Kitty has encountered a “: ob->action(): } }: class KungFuGuy: public Player { virtual void interactWith(Obstacle* ob) { cout « “KungFuGuy now battles against a “; ob->action(): } }: class Puzzle: public Obstacle { public: void actionO { cout « “Puzzle” « endl: } }: class NastyWeapon: public Obstacle { public: void actionO { cout « “NastyWeapon” « endl: } }: // Абстрактная фабрика: class GameElementFactory { 502 Глава 10 • Паттерны проектирования public: virtual Player* makePlayerO = 0; virtual Obstacle* makeObstacle() = 0: }: // Конкретные фабрики: class KittiesAndPuzzles : public GameElementFactory { public: virtual Player* makePlayerO { return new Kitty: } virtual Obstacle* makeObstacle() { return new Puzzle: } }: class KillAndDismember : public GameElementFactory { public: virtual Player* makePlayerO { return new Kun
Комментарии закрыты.
Последние комментарии