您的位置:首页 > 编程语言 > Java开发

java设计模式之代理模式

2016-06-21 09:09 459 查看
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");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  代理模式