外观模式-java
package u12; import java.util.Scanner; public class Client { public static void main(String[] args) { MainFrame f = new MainFrame(); f.fun(); } }
package u12; public class Os { public void display() { System.out.println("载入操作系统正常"); } }
package u12; public class Memory { public void display() { System.out.println("运行内存正常"); } }
package u12; public class MainFrame { private Memory memory = new Memory(); // 关联关系建立联系 private Cpu cpu = new Cpu(); private HardDisk harddisk = new HardDisk(); private Os os = new Os(); public void fun() { memory.display(); cpu.display(); harddisk.display(); os.display(); System.out.println("开机完成!"); } }
package u12; public class HardDisk { public void display() { System.out.println("硬盘读取正常"); } }
package u12; public class Cpu { public void display() { System.out.println("cpu运行正常"); } }