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();
    }

}

运行结果:

posted @ 2019-03-21 10:39  何浩源  阅读(248)  评论(0编辑  收藏  举报
//一下两个链接最好自己保存下来,再上传到自己的博客园的“文件”选项中