-
Notifications
You must be signed in to change notification settings - Fork 11
/
GoF3.h
44 lines (33 loc) · 828 Bytes
/
GoF3.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include <list>
namespace SingletonPattern::GoF3
{
class MazeFactory {
public:
static MazeFactory* Instance();
// existing interface goes here
protected:
MazeFactory() {}
private:
static MazeFactory* _instance;
};
MazeFactory* MazeFactory::_instance = 0;
class BombedMazeFactory : public MazeFactory {};
class EnchantedMazeFactory : public MazeFactory {};
MazeFactory* MazeFactory::Instance() {
if (_instance == 0) {
const char* mazeStyle = getenv("MAZESTYLE");
if (strcmp(mazeStyle, "bombed") == 0) {
_instance = new BombedMazeFactory;
}
else if (strcmp(mazeStyle, "enchanted") == 0) {
_instance = new EnchantedMazeFactory;
// ... other possible subclasses
}
else { // default
_instance = new MazeFactory;
}
}
return _instance;
}
}