DesignPattern/07.AdapterPattern/2.Code/AdapterPattern.h

63 lines
1000 B
C
Raw Permalink Normal View History

2019-10-22 00:24:54 +00:00
#ifndef __SINGLETON_H__
#define __SINGLETON_H__
#include <iostream>
#include <string.h>
#include <mutex>
using namespace std;
2021-10-28 13:26:15 +00:00
// 目标抽象类
2019-10-22 00:24:54 +00:00
class Controller
{
public:
Controller(){}
virtual ~Controller(){}
2019-10-22 00:24:54 +00:00
virtual void pathPlanning() = 0;
private:
};
2021-10-28 13:26:15 +00:00
// 适配者类DxfParser
2019-10-22 00:24:54 +00:00
class DxfParser
{
public:
DxfParser(){}
void parseFile(){
2021-10-28 13:26:15 +00:00
printf("Parse dxf file\n");
2019-10-22 00:24:54 +00:00
}
};
2021-10-28 13:26:15 +00:00
// 适配者类PathPlanner
2019-10-22 00:24:54 +00:00
class PathPlanner
{
public:
PathPlanner(){}
void calculate(){
2021-10-28 13:26:15 +00:00
printf("calculate path\n");
2019-10-22 00:24:54 +00:00
}
};
2021-10-28 13:26:15 +00:00
// 适配器类Adapter
2019-10-22 00:24:54 +00:00
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;
2019-10-22 00:24:54 +00:00
void pathPlanning(){
2021-10-28 13:26:15 +00:00
printf("pathPlanning\n");
2019-10-22 00:24:54 +00:00
dxfParser->parseFile();
pathPlanner->calculate();
}
private:
DxfParser *dxfParser;
PathPlanner *pathPlanner;
};
#endif //__SINGLETON_H__