bugfix: delete copy ctr and operator=

master
Qiangguo Feng 2021-10-19 18:22:17 +08:00 committed by GitHub
parent bc7425b152
commit ad8fb8e31c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 12 deletions

View File

@ -1,47 +1,48 @@
#ifndef __FACADE_PATTERN_H__ #ifndef __FACADE_PATTERN_H__
#define __FACADE_PATTERN_H__ #define __FACADE_PATTERN_H__
//子系统:内存 #include <stdio.h>
// subsystem: Memory
class Memory class Memory
{ {
public: public:
Memory(){} Memory(){}
void selfCheck(){ void selfCheck(){
printf("…………内存自检……\n"); printf("memory selfchecking......\n");
} }
}; };
//子系统:CPU // subsystem: CPU
class CPU class CPU
{ {
public: public:
CPU(){} CPU(){}
void run(){ void run(){
printf("…………运行CPU运行……\n"); printf("running cpu......\n");
} }
}; };
//子系统:硬盘 // subsystem: hardDisk
class HardDisk class HardDisk
{ {
public: public:
HardDisk(){} HardDisk(){}
void read(){ void read(){
printf("…………读取硬盘……\n"); printf("reading hardDisk......\n");
} }
}; };
//子系统:操作系统 // subsystem: OS
class OS class OS
{ {
public: public:
OS(){} OS(){}
void load(){ void load(){
printf("…………载入操作系统……\n"); printf("loading os.....\n");
} }
}; };
//外观类
class Facade class Facade
{ {
public: public:
@ -51,13 +52,25 @@ public:
hardDisk = new HardDisk(); hardDisk = new HardDisk();
os = new OS(); os = new OS();
} }
~Facade(){
delete memory;
delete cpu;
delete hardDisk;
delete os;
memory = nullptr;
cpu = nullptr;
hardDisk = nullptr;
os = nullptr;
}
Facade(const Facade& facade) = delete;
Facade operator=(const Facade& facade) = delete;
void powerOn(){ void powerOn(){
printf("正在开机……\n"); printf("power on……\n");
memory->selfCheck(); memory->selfCheck();
cpu->run(); cpu->run();
hardDisk->read(); hardDisk->read();
os->load(); os->load();
printf("开机完成!\n"); printf("ready!\n");
} }
private: private:
Memory *memory; Memory *memory;
@ -66,4 +79,4 @@ private:
OS *os; OS *os;
}; };
#endif //__FACADE_PATTERN_H__ #endif //__FACADE_PATTERN_H__