java代理设计模式

定义Subject接口

public interface Subject {
    void visit();
}

定义Subject接口实现类

public class RealSubject implements Subject {

    private String name = "byhieg";
    @Override
    public void visit() {
        System.out.println(name);
    }
}
public class ProxySubject implements Subject{

    private Subject subject;

    public ProxySubject(Subject subject) {
        this.subject = subject;
    }

    @Override
    public void visit() {
        subject.visit();
    }
}

客户端主程序

public class Client {

    public static void main(String[] args) {
        Subject subject = new ProxySubject(new RealSubject());
        subject.visit();
    }
}

你可能感兴趣的:(大数据笔记)