-
Notifications
You must be signed in to change notification settings - Fork 2
/
Decorator.cpp
54 lines (47 loc) · 1.05 KB
/
Decorator.cpp
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
#include <iostream>
class Component {
public:
virtual void operation() {};
};
class ConcCompA : public Component {
void operation() override {
std::cout << "ConcCompA" << std::endl;
}
};
class ConcCompB : public Component {
void operation() override {
std::cout << "ConcCompB" << std::endl;
}
};
class Decorator : public Component {
public:
Component *c;
Decorator(Component *com) {
this->c = com;
}
};
class ConDecA : public Decorator {
public:
ConDecA(Component* c): Decorator(c){};
void operation() override {
this->c->operation();
std::cout << "ConDecA" << std::endl;
}
};
class ConDecB : public Decorator {
public:
ConDecB(Component* c): Decorator(c){};
void operation() override {
this->c->operation();
std::cout << "ConDecB" << std::endl;
}
};
//int main() {
// Component* c = new ConDecA(new ConDecB(new ConcCompA));
// Component* c1 = new ConDecB(new ConDecA(new ConcCompB));
//
// c->print();
// c1->print();
//
// return 0;
//}