Java代理模式

interface Subject{
    void make();
}

class RealSubject implements Subject{
    public void make(){
        System.out.println("RealSubject start");
    }
}

class ProxySubject implements Subject{
    private Subject rs;
    
    public ProxySubject(Subject s){
        this.rs = s;
    }
    public void prepare(){
        System.out.println("ProxySubject start");
    }
    public void make(){
        this.prepare();
        rs.make();
        this.destroy();
    }
    public void destroy(){
        System.out.println("ProxySubject end");
    }
}

public class proxyDemo {
    public static void main(String[] args) {
        Subject s = new ProxySubject(new RealSubject());
        s.make();
    }
}

 

posted @ 2015-12-01 15:35  finalboss1987  阅读(185)  评论(0编辑  收藏  举报