Skip to content

Commit 2d84670

Browse files
适配器模式
1 parent d4f954c commit 2d84670

File tree

3 files changed

+38
-102
lines changed

3 files changed

+38
-102
lines changed

‎06-设计模式/0 我的总结.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@
2222
是不一样的。装饰者模式是实实在在的为对象增加新的职责和行为,而代理做的事情还是跟本体
2323
一样,最终都是设置 src。但代理可以加入一些“聪明”的功能,比如在图片真正加载好之前,先使用一张占位的 loadin 图片反馈给
2424

25-
状态模式和策略模式的关系
25+
状态模式和策略模式的关系
26+
27+
 装饰者模式和代理模式也不会改变原有对象的接口,但装饰者模式的作用是为了给对象
28+
增加功能。装饰者模式常常形成一条长的装饰链,而适配器模式通常只包装一次。代理
29+
模式是为了控制对对象的访问,通常也只包装一次。
30+
 外观模式的作用倒是和适配器比较相似,有人把外观模式看成一组对象的适配器,但外
31+
观模式最显著的特点是定义了一个新的接口
32+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
适配器模式主要用来解决两个已有接口之间不匹配的问题,它不考虑这些接口是怎样实现的,也不考虑它们将来可能会如何演化。
2+
适配器模式不需要改变已有的接口,就能够使它们协同作用。
3+
4+
<scripttype="text/javascript">
5+
vargoogleMap={
6+
show: function(){
7+
console.log('开始渲染谷歌地图');
8+
}
9+
};
10+
varbaiduMap={
11+
display: function(){
12+
console.log('开始渲染百度地图');
13+
}
14+
};
15+
varrenderMap=function(map){
16+
if(map.showinstanceofFunction){
17+
map.show();
18+
}
19+
};
20+
21+
// 适配器
22+
varbaiduMapAdapter={
23+
show: function(){
24+
returnbaiduMap.display();
25+
}
26+
};
27+
28+
renderMap(googleMap);// 输出:开始渲染谷歌地图
29+
renderMap(baiduMapAdapter);// 输出:开始渲染百度地图
30+
</script>

‎06-设计模式/temp/17/17.html‎

Lines changed: 0 additions & 101 deletions
This file was deleted.

0 commit comments

Comments
(0)