外观模式
属于结构型模式
外观模式其实就是将一段代码中不变的部分提炼出来,做成一个接口暴露给用户
为什么使用外观模式
降低访问复杂系统的内部子系统时的复杂度,减少系统相互依赖。提高灵活性.提高安全性
使用外观模式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| public class Facade { private DeviceA deviceA=new DeviceA(); private DeviceB deviceB=new DeviceB(); private DeviceC deviceC=new DeviceC();
public void methed(){ deviceA.method(); deviceB.method(); deviceC.method(); } }
public class DeviceA { public void method(){ System.out.println("执行DeviceA的方法"); } } public class DeviceB { public void method(){ System.out.println("执行DeviceB的方法"); } } public class DeviceC { public void method(){ System.out.println("执行DeviceC的方法"); } }
@Test public void testFacade() { Facade facade = new Facade(); facade.methed(); }
|
Anything can go right will go right