java 代理模式(模拟代购)

interface Isubject{
void buyAJ();
}
class realsubject implements Isubject{
public void buyAJ(){
System.out.println("买一双AJ,在代购平台付款");
}
} class proxysubject implements Isubject{
private Isubject subject;
public proxysubject(Isubject subject){
this.subject=subject; } public void beforebuy(){
System.out.println("去美国AJ专卖店排队抽号");
}
public void afterbuy(){
System.out.println("快递到客户手上");
} public void buyAJ(){
beforebuy();
subject. buyAJ();
afterbuy();
}
}
public class Test{ public static void main(String[] args) {
Isubject subject=new proxysubject(new realsubject() );
subject.buyAJ();
} }

运行结果:

java 代理模式(模拟代购)

上一篇:JVM基础系列第15讲:JDK性能监控命令


下一篇:web.xml配置error-page