1 类适配器
代码
using System;
using System.Collections.Generic;
interface Itest
{
void NewRequest();
}
class Method
{
public void OldRequest()
{
//DO;
}
}
class MethodAdpter:Method,Itest
{
public void NewRequest()
{
this.OldRequest();
}
}
public class MyClass
{
public static void Main()
{
Itest mytest=new MethodAdpter();
mytest.NewRequest();
}
}
using System.Collections.Generic;
interface Itest
{
void NewRequest();
}
class Method
{
public void OldRequest()
{
//DO;
}
}
class MethodAdpter:Method,Itest
{
public void NewRequest()
{
this.OldRequest();
}
}
public class MyClass
{
public static void Main()
{
Itest mytest=new MethodAdpter();
mytest.NewRequest();
}
}
2 对象适配器
代码
using System;
using System.Collections.Generic;
class Adaptee
{
public void OldRequest()
{
//TODO:
}
}
class Target
{
virtual public void NewRequest()
{
}
}
class Adapter:Target
{
private Adaptee adaptee=new Adaptee();
override public void NewRequest()
{
adaptee.OldRequest();
}
}
public class MyClass
{
public static void Main()
{
Target t=new Adapter();
t.NewRequest();
}
}
using System.Collections.Generic;
class Adaptee
{
public void OldRequest()
{
//TODO:
}
}
class Target
{
virtual public void NewRequest()
{
}
}
class Adapter:Target
{
private Adaptee adaptee=new Adaptee();
override public void NewRequest()
{
adaptee.OldRequest();
}
}
public class MyClass
{
public static void Main()
{
Target t=new Adapter();
t.NewRequest();
}
}