测试类:
1 public class Test { 2 3 public static void main(String[] args) { 4 Object obj = new ProxyObject(); 5 obj.action(); 6 } 7 } 1 public interface Object { 2 3 void action(); 4 } 1 public class ObjectImpl implements Object { 2 3 public void action() { 4 System.out.println("========"); 5 System.out.println("========"); 6 System.out.println("这是被代理的类"); 7 System.out.println("========"); 8 System.out.println("========"); 9 } 10 } 1 public class ProxyObject implements Object { 2 3 Object obj; 4 5 public ProxyObject() { 6 System.out.println("这是代理类"); 7 obj = new ObjectImpl(); 8 } 9 10 public void action() { 11 System.out.println("代理开始"); 12 obj.action(); 13 System.out.println("代理结束"); 14 } 15 }代理啦,代理模式...
转载于:https://www.cnblogs.com/huzi007/p/3988395.html