Java设计模式——代理模式

public interface People {
    public void work();
}

public class RealPeople implements People {
    public void work() {
        System.out.println("工作中...");
    }
}

/**
 * 代理类
 *
 */
public class Proxy implements People {

    private RealPeople realPeople;

    public Proxy(RealPeople realPeople) {
        this.realPeople = realPeople;
    }

    public void work() {
        System.out.println("before work...");
        realPeople.work();
        System.out.println("after work...");
    }
}

public class ProxyTest {
    public static void main(String[] args) {
        Proxy proxy = new Proxy(new RealPeople());
        proxy.work();
    }
}

 

posted @ 2017-12-20 18:04  小狼咕咕  阅读(194)  评论(0编辑  收藏  举报