设计模式:外观模式
2、外观模式的例子
?
//电脑的部件 class CPU { public void processData() { } } class Memory { public void load() { } } class HardDrive { public void readdata() { } } /* 外观 */ class Computer { private CPU cpu; private Memory memory; private HardDrive hardDrive; public Computer() { this.cpu = new CPU(); this.memory = new Memory(); this.hardDrive = new HardDrive(); } public void run() { cpu.processData(); memory.load(); hardDrive.readdata(); } } class User { public static void main(String[] args) { Computer computer = new Computer(); computer.run(); } }
?