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();
}
}
上一篇:[LeetCode] 331. Verify Preorder Serialization of a Binary Tree


下一篇:CSS Flexbox 学习指南、工具与框架