设计模式之代理模式
来源:互联网 发布:vb基础教程实验题目 编辑:程序博客网 时间:2024/06/18 01:50
自己写了一些关于代理模式的讲解,但确实没有如下这个例子讲的生动。但此内容有很多相同的博客,不知原创是哪一篇,我学习时看的是 http://yangguangfu.iteye.com/blog/815787 /** * @author BinCain * @version V1.0 * @Description: 定义了女人的function * @date 2017/10/26 0026 18:23 */public interface WomanInterface { /** * 抛媚眼 */ void ogleWithMan(); /** * 额----咳咳----ooxx */ void happyWithMan();}
public class PanJinLianClass implements WomanInterface { @Override public void ogleWithMan() { System.out.println("潘金莲抛媚眼-----"); } @Override public void happyWithMan() { System.out.println("潘金莲ooxx-----"); }}
/** * @author BinCain * @version V1.0 * @Description: 王婆老了,别人看不上她,所以她做了代理,接活让年轻的女子去做 * 因为王婆和潘金莲都实现了女人的功能,所以她知道潘金莲能完成任务 * @date 2017/10/26 0026 18:25 */public class WangPoClass implements WomanInterface { WomanInterface womanInterface; public WangPoClass(WomanInterface womanInterface) { this.womanInterface = womanInterface; } @Override public void ogleWithMan() { this.womanInterface.ogleWithMan(); } @Override public void happyWithMan() { this.womanInterface.happyWithMan(); }}
/** * @author BinCain * @version V1.0 * @Description: 西门庆来测试真伪 * @date 2017/10/26 0026 18:35 */public class XiMenQingTestClass { @Test public void testWithWoman(){ //联系王婆 ----- > 王婆把这个活给了潘金莲 (当然啦也可以找别人,只要西门庆看得上) WangPoClass wangPoClass = new WangPoClass(new PanJinLianClass()); //接下来看似是王婆在接活,其实干活的是潘金莲 wangPoClass.ogleWithMan(); wangPoClass.happyWithMan(); }}
西门庆测试结果如下:潘金莲抛媚眼-----潘金莲xxx-----Process finished with exit code 0
阅读全文
0 0
- 设计模式之代理模式
- 设计模式之代理模式
- 设计模式之代理模式
- 设计模式之代理模式
- 设计模式之-代理模式
- 设计模式之 代理模式
- 设计模式之代理模式
- 设计模式之代理模式
- 设计模式之代理模式
- 设计模式之代理模式
- 设计模式之代理模式
- 设计模式之代理模式
- 设计模式之代理模式
- 设计模式之-----代理模式
- 设计模式之代理模式
- 设计模式之-代理模式
- 设计模式之代理模式
- 设计模式之代理模式
- eclipse按装freemarker的插件
- 视频监控安防平台--国标28181-2016版本TCP码流沾包流程
- 【程序阅读笔记】C++图形界面五子棋
- 使用命令行将本地项目上传到git
- Spring 源码学习记录(无用自己看的)
- 设计模式之代理模式
- oracle创建分区表
- 编程之旅-ehcache.xml 加注释后报错
- Java并发编程实战笔记(2)-对象的共享
- Web服务评估工具Nikto
- 解决 Not allowed to load local resource 问题
- jsonp实例
- iOS clang: error:no such file or directory ~解决方法
- GPIO端口各种模式的区别