-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.cpp
50 lines (39 loc) · 777 Bytes
/
main.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
/*
* @FileName : adapter/main.cpp
* @CreateAt : 2022/4/13
* @Author : Inno Fang
* @Email : [email protected]
* @Description: Simple implementation of adapter pattern
*/
#include <iostream>
class Target {
public:
virtual void request() = 0;
virtual ~Target() = default;
};
class Adaptee {
public:
void specificRequest() {
std::cout << "Adaptee" << std::endl;
}
};
class Adapter : public Target {
public:
Adapter() {
_adaptee = new Adaptee();
}
~Adapter() {
delete _adaptee;
}
void request() override {
_adaptee->specificRequest();
};
private:
Adaptee *_adaptee;
};
int main() {
Target *target = new Adapter();
target->request();
delete target;
return 0;
}