结构
Convert the interface of a class into another interface clients expect. An adapter lets classes work together that could not otherwise because of incompatible interfaces.
将某个类的接口转换成客户端期望的另一个接口表示。适配器模式可以消除由于接口不匹配所造成的类兼容性问题。
interface ITarget {
void Request();
}
class Adapter : ITarget {
private readonly Adaptee _adaptee;
public Adapter(Adaptee adaptee) {
this._adaptee = adaptee;
}
void ITarget.Request() {
this._adaptee.PerformRequest();
}
}
class Adaptee {
public void PerformRequest() {
Console.WriteLine("Addaptee perform request.");
}
}
class Program {
static void Main(string[] args) {
ITarget target = new Adapter(new Adaptee());
target.Request();
Console.ReadLine();
}
}