add Facade Pattern

master
FengJungle 2019-10-26 15:43:05 +08:00
parent 6139398629
commit 8f0450d820
7 changed files with 87 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

View File

@ -0,0 +1,69 @@
#ifndef __FACADE_PATTERN_H__
#define __FACADE_PATTERN_H__
//子系统:内存
class Memory
{
public:
Memory(){}
void selfCheck(){
printf("…………内存自检……\n");
}
};
//子系统CPU
class CPU
{
public:
CPU(){}
void run(){
printf("…………运行CPU运行……\n");
}
};
//子系统:硬盘
class HardDisk
{
public:
HardDisk(){}
void read(){
printf("…………读取硬盘……\n");
}
};
//子系统:操作系统
class OS
{
public:
OS(){}
void load(){
printf("…………载入操作系统……\n");
}
};
//外观类
class Facade
{
public:
Facade(){
memory = new Memory();
cpu = new CPU();
hardDisk = new HardDisk();
os = new OS();
}
void powerOn(){
printf("正在开机……\n");
memory->selfCheck();
cpu->run();
hardDisk->read();
os->load();
printf("开机完成!\n");
}
private:
Memory *memory;
CPU *cpu;
HardDisk *hardDisk;
OS *os;
};
#endif //__FACADE_PATTERN_H__

View File

@ -0,0 +1,13 @@
#include <iostream>
#include "FacadePattern.h"
int main()
{
Facade *facade = new Facade();
facade->powerOn();
printf("\n\n");
system("pause");
return 0;
}

View File

@ -51,4 +51,8 @@
13.设计模式(十三)——装饰模式 13.设计模式(十三)——装饰模式
博客地址https://blog.csdn.net/sinat_21107433/article/details/102733023 博客地址https://blog.csdn.net/sinat_21107433/article/details/102733023
14.设计模式(十四)——外观模式
博客地址https://blog.csdn.net/sinat_21107433/article/details/102752643