-
Notifications
You must be signed in to change notification settings - Fork 11
/
Variant1.h
44 lines (33 loc) · 868 Bytes
/
Variant1.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
namespace SingletonPattern::Variant1
{
class IMazeFactory {};
class MazeFactory : public IMazeFactory {
public:
static IMazeFactory* Instance();
// existing interface goes here
protected:
MazeFactory() {}
private:
static IMazeFactory* _instance;
};
IMazeFactory* MazeFactory::_instance = 0;
class BombedMazeFactory : public IMazeFactory {};
class EnchantedMazeFactory : public IMazeFactory {};
IMazeFactory* 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;
}
}