装饰模式
2016-03-23 09:00
281 查看
装饰模式就是给一个对象增加一些新的功能,而且是动态的,要求装饰对象和被装饰对象实现同一个接口,装饰对象持有被装饰对象的实例!
/** * * @author: muyichun * @date : 2016年3月23日08:59:05 * @function: 装饰模式 */ public class Main{ public static void main(String[] args) { Sourceable source = new Source(); Sourceable obj = new Decorator(source); obj.method(); } } interface Sourceable{ public void method(); } class Source implements Sourceable{ @Override public void method() { System.out.println("the original method!"); } } class Decorator implements Sourceable{ private Sourceable source; public Decorator(Sourceable source){ super(); this.source = source; } @Override public void method() { System.out.println("before decorator!"); source.method(); System.out.println("after decorator!"); } }——贴上自己喜欢的代码
相关文章推荐
- 转载:Java虚拟机体系结构
- week4b:个人博客作业
- 2016年Web前端面试题目
- 软件工程结对开发作业01-02
- Esxi主机与VCSA从6.0升级至6.0 U2
- struts Tag标签使用
- eclipse ADT
- 【集合框架】JDK1.8源码分析之LinkedList(七)
- android中handler和bundle有什么区别和联系 都是用来传递消息吗都是信息的载体吗
- 战火引擎中如何写Lua逻辑脚本
- iOS面试必看,最全梳理
- apache+tomcat分布式搭建
- 技术选型——混编APP应用概述
- 技术选型——混编APP应用概述
- sql中in和exists的区别效率问题
- 为啥公司愿花更多钱从外面招人
- 移动前端头部标签(HTML5 head meta)
- 网易2016春招实习笔试总结
- Matlab dir函数
- Windows办公技能——在当前文件夹中打开命令行窗口