Appearance
适配器
一个类转换成另外一种接口。(好比显示信号转换头,可以把HDMI信号转换成VGA)
小例子
javascript
class TencentMap{
show(){
console.log("展示")
}
}
class BaiduMap{
display(){
console.log("渲染")
}
}
class TencentAdapter extends TencentMap{
constructor(){
super()
}
display(){
this.show()
}
}
function renderMap(map){
map.display()
}
renderMap(new TencentAdapter())
renderMap(new BaiduMap())