forked from FengJungle/DesignPattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdapterPattern.h
More file actions
63 lines (57 loc) · 1000 Bytes
/
AdapterPattern.h
File metadata and controls
63 lines (57 loc) · 1000 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
62
63
#ifndef __SINGLETON_H__
#define __SINGLETON_H__
#include <iostream>
#include <string.h>
#include <mutex>
using namespace std;
// 目标抽象类
class Controller
{
public:
Controller(){}
virtual ~Controller(){}
virtual void pathPlanning() = 0;
private:
};
// 适配者类DxfParser
class DxfParser
{
public:
DxfParser(){}
void parseFile(){
printf("Parse dxf file\n");
}
};
// 适配者类PathPlanner
class PathPlanner
{
public:
PathPlanner(){}
void calculate(){
printf("calculate path\n");
}
};
// 适配器类Adapter
class Adapter:public Controller
{
public:
Adapter(){
dxfParser = new DxfParser();
pathPlanner = new PathPlanner();
}
~Adapter(){
delete dxfParser;
delete pathPlanner;
}
Adapter(const Adapter& other) = delete;
Adapter& operator=(const Adapter& ) = delete;
void pathPlanning(){
printf("pathPlanning\n");
dxfParser->parseFile();
pathPlanner->calculate();
}
private:
DxfParser *dxfParser;
PathPlanner *pathPlanner;
};
#endif //__SINGLETON_H__