在wiki上面看到李建忠老师的饰品,觉得讲解的很不错
做个记录
内部子系统的任何变化不会影响到Facade接口的变化
Facade设计模式更注重从架构的层次去看整个系统,而不是单个类的层次。Facade很多时候更是一种架构设计模式
Facade模式注重简化接口
Adapter模式注重转换接口
Bridge模式注重分离接口
Decorator注重稳定接口的前提下为对象扩展功能
class Bodywork { /** * */ public void bAction1() { } /** * */ public void bAction2() { } } class Controller { /** * */ public void cAction1() { } /** * */ public void cAction2() { } } class Engine { /** * */ public void eAction1() { } /** * */ public void eAction2() { } } class Wheel { /** * */ public void wAction1() { } /** * */ public void wAction2() { } } public class TankFacade { /** * 轮子数量. */ private static final int WHEEL_NUM = 4; /** * 引擎数量. */ private static final int ENGINES_NUM = 4; /** * 轮子. */ private Wheel[] wheels = new Wheel[WHEEL_NUM]; /** * 引擎. */ private Engine[] engines = new Engine[ENGINES_NUM]; /** * 车体. */ private Bodywork bodywork = new Bodywork(); /** * 控制器. */ private Controller controller = new Controller(); /** * */ public void start() { //坦克启动 } /** * */ public void stop() { //坦克停止 } /** * */ public void run() { //坦克行驶 } }