DesignPattern/11.FacadePattern/2.Code/FacadePattern.h

83 lines
1.1 KiB
C
Raw Normal View History

2019-10-26 07:43:05 +00:00
#ifndef __FACADE_PATTERN_H__
#define __FACADE_PATTERN_H__
2021-10-19 10:22:17 +00:00
#include <stdio.h>
// subsystem: Memory
2019-10-26 07:43:05 +00:00
class Memory
{
public:
Memory(){}
void selfCheck(){
2021-10-19 10:22:17 +00:00
printf("memory selfchecking......\n");
2019-10-26 07:43:05 +00:00
}
};
2021-10-19 10:22:17 +00:00
// subsystem: CPU
2019-10-26 07:43:05 +00:00
class CPU
{
public:
CPU(){}
void run(){
2021-10-19 10:22:17 +00:00
printf("running cpu......\n");
2019-10-26 07:43:05 +00:00
}
};
2021-10-19 10:22:17 +00:00
// subsystem: hardDisk
2019-10-26 07:43:05 +00:00
class HardDisk
{
public:
HardDisk(){}
void read(){
2021-10-19 10:22:17 +00:00
printf("reading hardDisk......\n");
2019-10-26 07:43:05 +00:00
}
};
2021-10-19 10:22:17 +00:00
// subsystem: OS
2019-10-26 07:43:05 +00:00
class OS
{
public:
OS(){}
void load(){
2021-10-19 10:22:17 +00:00
printf("loading os.....\n");
2019-10-26 07:43:05 +00:00
}
};
class Facade
{
public:
Facade(){
memory = new Memory();
cpu = new CPU();
hardDisk = new HardDisk();
os = new OS();
}
2021-10-19 10:22:17 +00:00
~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;
2019-10-26 07:43:05 +00:00
void powerOn(){
2021-10-19 10:22:17 +00:00
printf("power on……\n");
2019-10-26 07:43:05 +00:00
memory->selfCheck();
cpu->run();
hardDisk->read();
os->load();
2021-10-19 10:22:17 +00:00
printf("ready!\n");
2019-10-26 07:43:05 +00:00
}
private:
Memory *memory;
CPU *cpu;
HardDisk *hardDisk;
OS *os;
};
2021-10-19 10:22:17 +00:00
#endif //__FACADE_PATTERN_H__