大概理解就是转接头把
比如现在小米9手机抛弃了正常的耳机孔,需要一个适配器才能使用正常的耳机
或者Type-3的数据线苹果手机不能用,通过一个适配器,就可以让苹果手机使用了
class Me {
constructor() {
this.adapter = new Adapter()
}
phoneCharge() {
return this.adapter.request()
}
}
class Adapter {
constructor() {
this.type3 = new Type3()
}
request() {
const info = this.type3.getPlug()
return `${info} => 转换器 => usb-c`
}
}
class Type3 {
getPlug () {
return `Type-3`
}
}
const me = new Me()
me.phoneCharge()
vue的计算属性就是适配器模式