静态代理模式
代理模式(Proxy),为其他对象提供一种代理以控制对这个对象的访问
代理模式说白了就是”真实对象“的代表,在访问对象时引入一定程度的间接性,
因为这个间接性可以附加多种用途。
public class TestProxy { public static void main(String[] args) { // TODO Auto-generated method stub Action a1 =new UserAction(); ActionProxy a2 = new ActionProxy(a1); a2.action(); } } interface Action{ public void action(); } class UserAction implements Action{ public void action() { System.out.println("用户开始工作"); } } class ActionProxy implements Action{ private Action targt; public ActionProxy(Action targt) { this.targt = targt; } public void action() { long start = System.currentTimeMillis(); targt.action(); long end = System.currentTimeMillis(); System.out.println(start-end); } }