先写老系统的代码
public class Adaptee {
public void SpecificRequest()
{
System.out.println("特殊请求!");
}
}
在写新系统的代码
public class Target {
public void Request()
{
System.out.println("普通请求!");
}
}
再写代理类的代码
public class Adapter extends Target{
private Adaptee adaptee = new Adaptee();
@Override
public void Request() {
// TODO Auto-generated method stub
adaptee.SpecificRequest();
}
}
测试代码
public class Program {
public static void main(String[] args) {
// TODO Auto-generated method stub
Target target = new Adapter();
target.Request();
}
}