add AdapterPattern

master
FengJungle 2019-10-22 08:24:54 +08:00
parent 72d156e4c0
commit bb9400b945
5 changed files with 72 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -0,0 +1,56 @@
#ifndef __SINGLETON_H__
#define __SINGLETON_H__
#include <iostream>
#include <string.h>
#include <mutex>
using namespace std;
//目标抽象类
class Controller
{
public:
Controller(){}
virtual void pathPlanning() = 0;
private:
};
//适配者类DxfParser
class DxfParser
{
public:
DxfParser(){}
void parseFile(){
printf("解析文件提取数据\n");
}
};
//适配者类PathPlanner
class PathPlanner
{
public:
PathPlanner(){}
void calculate(){
printf("计算加工路径\n");
}
};
//适配器类Adapter
class Adapter:public Controller
{
public:
Adapter(){
dxfParser = new DxfParser();
pathPlanner = new PathPlanner();
}
void pathPlanning(){
printf("路径规划:\n");
dxfParser->parseFile();
pathPlanner->calculate();
}
private:
DxfParser *dxfParser;
PathPlanner *pathPlanner;
};
#endif //__SINGLETON_H__

View File

@ -0,0 +1,11 @@
#include <iostream>
#include "AdapterPattern.h"
int main()
{
Controller *controller = new Adapter();
controller->pathPlanning();
system("pause");
return 0;
}

View File

@ -36,3 +36,7 @@
09.设计模式(九)——单例模式
博客地址https://blog.csdn.net/sinat_21107433/article/details/102649056
10.设计模式(十)——适配器模式
博客地址https://blog.csdn.net/sinat_21107433/article/details/102656617