当前位置:网站首页>Understanding adapter mode from home office | community essay solicitation
Understanding adapter mode from home office | community essay solicitation
2022-06-29 17:10:00 【InfoQ】
One
var googleMap={
show:function(){
console.log(' Start rendering google Map ');
}
};
var baiduMap={
show:function(){
console.log(' Start rendering Baidu map ');
}
};
var renderMap=function(map){
if(map.show instanceof Function){
map.show();
}
};
renderMap(googleMap); // Output : Start rendering google Map
renderMap(baiduMap); // Output : Start rendering Baidu map
var googleMap={
show:function(){
console.log(' Start rendering google Map ');
}
};
var baiduMap={
display:function(){
console.log(' Start rendering Baidu map ');
}
};
var baiduMapAdapter={
show:function(){
return baiduMap.display();
}
};
var renderMap=function(map){
if(map.show instanceof Function){
map.show();
}
};
renderMap(googleMap);
renderMap(baiduMapAdapter);
Two
var getGuangdongCity=function(){
var guangdongCity=[
{name:'shenzhen',id:11},
{name:'guangzhou',id:12}
];
return guangdongCity;
};
var render=function(fn){
console.log(' Start rendering the map of Guangdong Province ');
document.write(JSON.stringify(fn()));
};
render(getGuangdongCity());
var guangdongCity={
shenzhen:11,
guangzhou:12,
zhuhai:13
};
var getGuangdongCity=function(){
var guangdongCity=[
{name:'shenzhen',id:11},
{name:'guangzhou',id:12}
];
return guangdongCity;
};
var render=function(fn){
console.log(' Start rendering the map of Guangdong Province ');
document.write(JSON.stringify(fn()));
};
var addressAdapter=function(oldAddressfn){
var address={},
oldAddress=oldAddressfn();
for(var i=0,c;c=oldAddress[i++];){
address[c.name]=c.id; // Convert to a new data format
}
};
render(addressAdapter(getGuangdongCity));
- Adapter pattern is mainly used to solve the problem of mismatch between two existing interfaces , It doesn't consider how these interfaces are implemented , And regardless of how they might evolve in the future . Adapter mode does not need to change the existing interface , We can make them work together .
- Decorator mode and proxy mode also do not change the interface of the original object , But the role of decorator mode is to add function to the object . The decorator pattern often forms a long decorative chain , The adapter mode is usually packaged only once . Proxy mode is to control access to objects , Usually it's only packed once .
- The function of appearance mode is similar to that of adapter , Some people think of appearance patterns as adapters for a set of objects , But the most striking feature of the appearance pattern is the definition of a new interface .
边栏推荐
- A user level thread library based on C language
- An error is reported in the Flink SQL rownumber. Who has met him? How to solve it?
- Interrupt怎么用
- 疫情居家外包项目之协作开发| 社区征文
- Kali installation tutorial 2020
- Greedy Apple plans to raise the price of iphone14, which will provide opportunities for Chinese mobile phones
- windows平台下的mysql启动等基本操作
- Inheritablethreadlocal resolves message loss during message transmission between parent and child threads in the thread pool
- Word2vec vector model of Wiki Chinese corpus based on deep learning
- Advanced MySQL - storage engine
猜你喜欢
【无标题】
SpingMVC请求和响应
Greedy Apple plans to raise the price of iphone14, which will provide opportunities for Chinese mobile phones
ICML 2022 | transferable imitation learning method based on decoupling gradient optimization
基于汇编实现的流载体的LSB隐藏项目
微信小程序开发储备知识
疫情居家外包项目之协作开发| 社区征文
High landing pressure of "authorization and consent"? Privacy computing provides a possible compliance "technical solution"
InheritableThreadLocal 在线程池中进行父子线程间消息传递出现消息丢失的解析
垃圾收集器
随机推荐
微信小程序开发储备知识
InheritableThreadLocal 在线程池中进行父子线程间消息传递出现消息丢失的解析
从居家办公中感悟适配器模式 | 社区征文
线段树、树状数组模板(复制粘贴确实好用)
PCB板框的绘制——AD19
卷妹带你学数据库---5天冲刺Day1
SAAS 服务的优势都有哪些
Why does selenium become the first choice for web automated testing? (source code attached)
New feature of C11 - Auto and decltype type type indicators
6.25atcoderabc257e - addition and multiplication 2
Basics | draw arcs in the physics engine
英联邦国家有哪些
2022 software evaluator examination outline
最高81.98%!超百所“双一流”高校本科深造率公布
Problem solving metauniverse, multi communication scheme in online games
力扣解法汇总535-TinyURL 的加密与解密
使用kalibr標定工具進行單目相機和雙目相機的標定
首批!腾讯云通过中国信通院政务协同平台解决方案能力评估
我的远程办公初体验 | 社区征文
MySQL highly available cluster – MHA