forked from yogykwan/design-patterns-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobserver.h
More file actions
61 lines (48 loc) · 974 Bytes
/
observer.h
File metadata and controls
61 lines (48 loc) · 974 Bytes
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// Created by Jennica on 2017/1/2.
//
#ifndef DESIGN_PATTERNS_OBSERVER_H
#define DESIGN_PATTERNS_OBSERVER_H
#include <string>
#include <vector>
class Notifier;
class Observer {
public:
Observer() {}
Observer(std::string);
virtual ~Observer() {}
void SetNotifier(Notifier *);
virtual void Update() = 0;
protected:
std::string name_;
Notifier *notifier_;
};
class StockObserver: public Observer {
public:
StockObserver() {}
StockObserver(std::string);
void Update();
};
class NbaObserver: public Observer {
public:
NbaObserver() {}
NbaObserver(std::string);
void Update();
};
class Notifier {
public:
virtual ~Notifier() {}
void Attach(Observer *);
void Detach(Observer *);
void SetState(std::string);
std::string GetState();
void Notify();
protected:
std::vector <Observer*> observers_;
std::string state_;
};
class Secretary: public Notifier {
};
class Boss: public Notifier {
};
#endif //DESIGN_PATTERNS_OBSERVER_H