设计模式(九):外观模式

  定义:外观模式提供了统一的接口,用来访问子系统中的一群接口。跟适配器模式是为了符合用户的意图而改变接口不同,外观模式只简化子系统的一群接口而已。

class CPU {
public:
        void freeze() { ... }
        void jump(long position) { ... }
        void execute() { ... }
}
 
class Memory {
public:
        void load(long position, char* data) {
                ...
        }
}
 
class HardDrive {
public:
        char* read(long lba, int size) {
                ...
        }
}
 
/* Façade */
 
class Computer {
public:
        void startComputer() {
                cpu.freeze();
                memory.load(BOOT_ADDRESS, hardDrive.read(BOOT_SECTOR, SECTOR_SIZE));
                cpu.jump(BOOT_ADDRESS);
                cpu.execute();
        }
}
 
/* Client */
 
class You {
public:
        void start(String[] args) {
                Computer facade = new Computer();
                facade.startComputer();
        }
}
原文地址:https://www.cnblogs.com/bracken/p/3067913.html