标签:img over rgs color void min com chef public
//设计模式之静态代理模式 interface Chefer { void BecomeChefer(); } //小明想当厨师,天天做好吃的 class XiaoMing implements Chefer { @Override public void BecomeChefer() { System.out.println("我要学厨艺"); } } //我是中介,钱出够了什么都妥了 class Proxy implements Chefer { //静态代理模式需要把对象传进来 private XiaoMing xiaoMing; Proxy(XiaoMing xiaoMing) { this.xiaoMing = xiaoMing; } @Override public void BecomeChefer() { System.out.println("我是中介,你想要干啥"); xiaoMing.BecomeChefer(); System.out.println("先给钱"); } } public class Demo4 { public static void main(String[] args) { Proxy proxy = new Proxy(new XiaoMing()); proxy.BecomeChefer(); } } 输出: 我是中介,你想要干啥 我要学厨艺 我开始帮你找啦
标签:img over rgs color void min com chef public
原文地址:https://www.cnblogs.com/lzh110/p/9462073.html