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(); } }
运行结果: