java设计模式之代理模式

来源:互联网 发布:蚌埠巨人网络 编辑:程序博客网 时间:2024/05/16 13:44

public interface Sourceable{

public void method();

}


public class Source implements Sourceable{

@Override

public void method(){

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

}

}


public class Proxy implements Sourceable{

private Source source;

public Proxy(Source source){

this source = source;


@Override

public void method(){

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

}


public void after(){

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

}

public void before(){

before();

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

after();

}

}

}


public class TestProxy{

public static void main(String[] args){

Sourceable proxy = new Proxy();

proxy.method();

}

}

0 0