java设计模式之代理模式

来源:互联网 发布:js正则判断是否是数字 编辑:程序博客网 时间:2024/06/03 21:38

public interface Sourceable{

public void method();

}


public class Source implements Sourceable{

@Override

public void method(){

System.out.println("this is the source method!");

}

}

public class Proxy implements Sourceable{

private Source source;

public Proxy(){

super();

this.source = new Source();

}

@Override

public void method(){

System.out.println("this is the proxy method");

before();

source.method();

after();

}


public void before(){

System.out.println("this is the before method");

}


public void after(){

System.out.println("this is the after method");

}


}


public class TestProxy{

public static void main(String[] args){

Sourceable sourceable = new Proxy();

sourceable.method();

}

}

public void before(){

System.out.println("this is the before method");

}

0 0