【阶段总结】适配器模式&外观模式
来源:互联网 发布:手机拦截广告软件 编辑:程序博客网 时间:2024/06/05 17:00
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() ...{
//初始化发动机
}
public void start(Key key) ...{
Doors doors = new Doors();
boolean authorized = key.turns();
if (authorized)
...{
engine.start();
updateDashboardDisplay();
doors.lock();
}
}
public void updateDashboardDisplay() ...{
//更新显示
}
}
public float getTemp() ...{
return station.getTemperature();
}
被解耦的客户才是快乐的客户。
public class TurkeyAdapter implements Duck ...{
Turkey turkey;
public TurkeyAdapter(Turkey turkey) ...{
this.turkey = turkey;
}
public void quack() ...{
turkey.gobble();
}
public void fly() ...{
for (int i=0; i<5; i++)
...{
turkey.fly();
}
}
}
-->
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() ...{
//初始化发动机
}
public void start(Key key) ...{
Doors doors = new Doors();
boolean authorized = key.turns();
if (authorized)
...{
engine.start();
updateDashboardDisplay();
doors.lock();
}
}
public void updateDashboardDisplay() ...{
//更新显示
}
}
public float getTemp() ...{
return station.getTemperature();
}
被解耦的客户才是快乐的客户。
public class TurkeyAdapter implements Duck ...{
Turkey turkey;
public TurkeyAdapter(Turkey turkey) ...{
this.turkey = turkey;
}
public void quack() ...{
turkey.gobble();
}
public void fly() ...{
for (int i=0; i<5; i++)
...{
turkey.fly();
}
}
}
- 【阶段总结】适配器模式&外观模式
- 适配器模式&外观模式
- 适配器模式、外观模式
- 适配器模式 && 外观模式
- 适配器模式,外观模式
- 适配器和外观模式
- 适配器和外观模式
- 适配器与外观模式
- 适配器模式和外观模式
- 适配器模式与外观模式
- 适配器模式和外观模式
- 适配器模式和外观模式
- 适配器模式和外观模式
- 适配器模式和外观模式
- 适配器模式和外观模式
- 外观模式和适配器模式
- 适配器模式与外观模式
- 适配器模式与外观模式
- 一个图标搜索网站
- 在Reporting Service中实现Drill down
- asp.net(c#)生成验证码 点击可刷新
- SQL SERVER中用存储过程验证登陆正确性
- 关于虚拟目录继承根Web.Config的问题解决办法
- 【阶段总结】适配器模式&外观模式
- 如何用vb将计算结果输出到word中?
- 卡尔曼滤波器
- 利用google的接口在网站嵌入搜索
- 遍历页面控件的几种方法
- 利用MPICH2计算矩阵相乘的简单算法
- C# 创建临时文件
- 编译php错误代码configure: error: Try adding --with-zlib-dir=. Please check config.log for more information.
- 樱花大战常见问题解答