//アダプタモードは、クライアントが期待するインターフェイスを定義するため、元のインターフェイスと一致しない2つのクラスが連携して機能することができます
インターフェースAA {
doA:()=>文字列;
}
インターフェースBB {
doB:()=>文字列;
}
インターフェースCC {
doC:()=>文字列;
}
クラスaaaはAA {
prayerA():文字列{
「AA」を返します。
}
}
クラスbbbはBBを実装します{
doB():文字列{
「BB」を返します。
}
}
//特定のコンポーネント
クラスccccはCC {
doC():string {
「CC」を返します。
}
}
クラスshiyongzhe {
プライベートaa:AA = null;
プライベートBB:BB = null;
プライベートcc:CC = null;
プライベートa:文字列= null;
プライベートb:文字列= null;
プライベートc:文字列= null;
コンストラクター(aa:AA、bb:BB、cc:CC){
this.aa = aa;
this.bb = bb;
this.cc = cc;
this.a = this.aa.doA();
this.b = this.bb.doB();
this.c = this.cc.doC();
}
getInfo1():string {
this.aを返す;
}
getInfo2():string {
this.bを返します。
}
}
let aa = new aaa();
bb = new bbb();
let ccc = new cccc();
let cobj:shiyongzhe = new shiyongzhe(aa、bb、ccc);
YBLog.log( "Test"、cobj.getInfo1());
//利点:関連しないクラスは、この役割に適応している限り、1回混合できます。クラスの透明性を高め、クラスの再利用と柔軟性を向上させます。
//短所:解決策は、サービス中のプロジェクトの問題です。