静态代理

122 阅读1分钟
package com.gavin.exer;

public class StaticProxyExample {
  static class Target{
    public void execute(){
      System.out.println("目标方法已执行");
    }
  }
  static class Proxy{
    Target target;
    public Proxy(Target target){
      this.target = target;
    }
    public void proxyMethod(){
      System.out.println("代理前");
      this.target.execute();
      System.out.println("代理后");
    }
  }

  public static void main(String[] args) {
    Target target = new Target();
    Proxy proxy = new Proxy(target);
    proxy.proxyMethod();
  }
}