1、what
隐藏系统的复杂性,并向客户端提供了一个客户端可以访问系统的接口;
2、解决什么问题?
简化客户端的使用,服务端只需要提供一个高级抽象接口;
3、案例
去医院看病,可能要去挂号、门诊、划价、取药,让患者或患者家属觉得很复杂,如果有提供接待人员,只让接待人员来处理,就很方便
4、
package com.an.facade; public interface Drawer { void draw(); } package com.an.facade; public class CycleDrawer implements Drawer{ public void draw() { System.out.println("cycle draw..."); } } package com.an.facade; public class SquareDrawer implements Drawer{ public void draw() { System.out.println("square draw..."); } } package com.an.facade; /** * 提供给调用方的高级抽象 * 封装了具体的实现细节,eg:drawCycle... */ public class DrawerFacade { private CycleDrawer cycleDrawer; private SquareDrawer squareDrawer; public DrawerFacade(){ this.cycleDrawer=new CycleDrawer(); this.squareDrawer=new SquareDrawer(); } public void drawCycle(){ cycleDrawer.draw(); } public void drawSquare(){ squareDrawer.draw(); } } package com.an.facade; public class Test { public static void main(String[] args) { DrawerFacade drawerFacade=new DrawerFacade(); drawerFacade.drawCycle(); drawerFacade.drawSquare(); } } 结果: cycle draw... square draw...