标签:ring pac vat gen str int div void inter
静态代理设计模式,由代理对象代理所有真实对象的功能,但是当代理功能比较多时,代理类中方法需要写很多,
package com.fd.proxy; public interface Func { public void A(); }
真实类
package com.fd.proxy; public class Proxy implements Func{ public void A() { System.out.println("A"); } }
代理类
package com.fd.proxy; public class Agent implements Func { private Proxy proxy = new Proxy(); @Override public void A() { System.out.println("Agent Before A"); proxy.A(); System.out.println("Agent After A"); } }
测试
package com.fd.proxy; public class TestMain { public static void main(String[] args) { Agent agent = new Agent(); agent.A(); } }
标签:ring pac vat gen str int div void inter
原文地址:https://www.cnblogs.com/spark-quant/p/9694806.html