package proxy;/** * 抽象主题,定义主要功能 */public interface Subject { public void operate();}
package proxy;public class Proxy implements Subject{ private Subject subject; public Proxy(Subject subject) { this.subject = subject; } public void operate() { System.out.println("before operate......"); subject.operate(); System.out.println("after operate......"); }}
package proxy;public class RealSubject implements Subject{ public void operate() { System.out.println("realsubject operatestarted......"); }}
package proxy;public class Client { public static void main(String[] args) { Subject subject = new RealSubject(); Proxy proxy = new Proxy(subject); proxy.operate(); }}