java设计模式-代理模式

package proxy;

/**
 * 抽象主题,定义主要功能
 */
public interface Subject {
     public void operate();
}
package proxy;

public class Proxy implements Subject{

    private Subject subject;
    
    public Proxy(Subject subject) {
        this.subject = subject;
    }
    
    public void operate() {
        System.out.println("before operate......");
        subject.operate();
        System.out.println("after operate......");
    }
}
package proxy;

public class RealSubject implements Subject{
    public void operate() {
        System.out.println("realsubject operatestarted......");
    }
}
package proxy;

public class Client {
    public static void main(String[] args) {
         Subject subject = new RealSubject();
            Proxy proxy = new Proxy(subject);
            proxy.operate();
    }
}

 

posted on 2016-09-01 16:15  悄悄的来,匆匆的走  阅读(146)  评论(0编辑  收藏  举报

导航