If you need ,you can make a conlusion whenever you need. --> An Andapter converts an interface Facade still allows low level access Disadvantage of "the Principle of Least Knowledge": too many wrappers "the Principle of Least Knowledge": Law of Demeter A facade simplifiers an interface Decorator called Adapter this"simple pass through" One advantage of Facade: decoupling Principle that wasn't as easy as it sounded: least knowledge A Decorator adds new behavior Example that violates the Principle of Least Knowledge: System.out.println Adapter client uses the target interface An Adapter and a Decorator can be said to wrap an object 适配器模式: 将一个类的接口,转换成客户期望的另一个接口。适配器让原本不兼容的类可以合作无间。 外观模式: 提供了一个统一的接口,用来访问子系统中的一群接口。外观定义了一个高层接口,让子系统更容易使用。 OO原则: 只和朋友交谈 Sutra Code as follows --> publi class Car ...{ Engine engine; //其他实例变量 public Car() ...{ //初始化发动机 } publicvoid start(Key key) ...{ Doors doors =new Doors(); boolean authorized = key.turns(); if (authorized) ...{ engine.start(); updateDashboardDisplay(); doors.lock(); } } publicvoid updateDashboardDisplay() ...{ //更新显示 } } publicfloat getTemp() ...{ return station.getTemperature(); } 被解耦的客户才是快乐的客户。 publicclass TurkeyAdapter implements Duck ...{ Turkey turkey; public TurkeyAdapter(Turkey turkey) ...{ this.turkey = turkey; } publicvoid quack() ...{ turkey.gobble(); } publicvoid fly() ...{ for (int i=0; i<5; i++) ...{ turkey.fly(); } } }