标签:proxy eal subject static ace rgs over nts 代理类
//代理类和实际对象类共同实现的接口
public interface Subject {
void dancing();
void singing();
}
//实际对象类
public class RealObject implements Subject{
@Override
public void dancing() {
System.out.println("跳舞");
}
@Override
public void singing() {
System.out.println("唱歌");
}
}
//代理类
public class Proxy implements Subject {
RealObject realObject;
public Proxy() {
realObject = new RealObject();
}
@Override
public void dancing() {
realObject.dancing();
}
@Override
public void singing() {
realObject.singing();
}
}
//客户端类
public class Client {
public static void main(String[] args) {
Proxy proxy = new Proxy();
proxy.dancing();
proxy.singing();
}
}
标签:proxy eal subject static ace rgs over nts 代理类
原文地址:https://www.cnblogs.com/yfy-/p/11961180.html