代理模式

代理模式

静态代理

public interface Subject {

        void request(String var);

}

public class RealSubjectimplements Subject {

@Override

    public void request(String var) {

System.out.println("RealSubject="+var);

    }

}

public class StaticProxyimplements Subject {

SubjectrealSubject;

    public StaticProxy(Subject realSubject) {

this.realSubject = realSubject;

    }

//验证参数

    public void validParam(String param){

System.out.println("这个参数是正确的"+param);

    }

@Override

    public void request(String var) {

this.validParam(var);

        realSubject.request(var);

    }

public static void main(String[] args) {

Subject target =new RealSubject();

        Subject proxy =new StaticProxy(target);

        proxy.request("请付款");

    }

}

你可能感兴趣的:(代理模式)