适配器模式(Adapter Pattern) 是将一个接口转换成客户希望的另一个接口,适配器模式使接口不兼容的那些类可以一起工作,其别名为包装器(Wrapper)。适配器模式既可以作为类结构型模式,也可以作为对象结构型模式。
适配器模式包含如下角色:
class Adapter {test() {return '旧接口';}}class Target {constructor() {this.adapter = new Adapter();}test() {let info = this.adapter.test();return `适配${info}`;}}const target = new Target();// '适配旧借口'console.log(target.test());