用通俗的话理解设计模式--Decorator pattern
来源:互联网 发布:阿振网络随笔 编辑:程序博客网 时间:2024/06/05 09:08
it's much messy to understand Decorator pattern.
The first intend of this pattern is providing powerful functions rather by inheriting but by composition. I think this key point is under my understable line. The second intend of this pattern is to utlize the power of extension in runtime rather than in compile time.
The second intend is acutally to use the power of the abstract class and to create an instance of a derived class that inherits an abstract class.
so what make my mind messy is that the abstract class, and the compile time versus the runtime.
My question1:
if there are two classes derived from the same abstract class, for example,
public abstract class Beverage{ public abstract string GetDescription(); }public abstract class class1:Beverage{ public override string GetDescription() { return "class1"; }}public abstract class class2 : Beverage{ public override string GetDescription() { return "class2"; }}
what does it means when I code like this following
Beverage test=new class1();test=new class2();
My question2:
when I inherit behavior by subclassing, that behavior is set statically at compile time. In addition, all subclasses must inherit the same behavior. If however, I can extend an object's behavior through composition, then I can do this danamically at runtime.
Whatever, the decorator pattern could add responsibilities to object dynamically which seems very attractive and glory. What'more, to multiply an object's responsiblities is worked by a step-down instance creation.
A gold rule "Open to extension and closed to modifcaiton " is also featured by the decorator pattern
- 用通俗的话理解设计模式--Decorator pattern
- 用通俗的话理解设计模式-Command pattern
- 用通俗的话理解设计模式-Template Method pattern
- 用通俗的话理解设计模式--Adapter pattern to Facade pattern
- 设计模式--Decorator Pattern
- 设计模式之Decorator Pattern
- 设计模式—Decorator Pattern
- 设计模式通俗理解
- 设计模式[6] Decorator Pattern 装饰模式
- 设计模式-装饰者模式(Decorator Pattern)
- 设计模式-装饰模式(Decorator Pattern)
- 设计模式之装饰模式(Decorator Pattern)
- 设计模式心得:装饰模式 (decorator pattern)
- 设计模式-装饰模式(Decorator Pattern)
- 设计模式之装饰模式--- Pattern Decorator
- 设计模式_装饰模式(Decorator Pattern)
- 设计模式【装饰模式Decorator Pattern】
- 设计模式实现(八): Decorator Pattern
- Python定时任务框架APScheduler
- SQL SERVER 2005附加只有MDF(无LOG)时报错解决方法
- Linux网络编程:TCP服务器(单进程多用户),使用select方法实现
- DB数据静态化json文件,用Mybatis产生json文件,需要优化(大牛就别拍砖了)
- J2SE基础夯实系列之父类引用指向子类对象
- 用通俗的话理解设计模式--Decorator pattern
- FindWindow
- JavaScript培训
- JavaScript学习路上---js 核心概念
- 使用jQuery easyUI 创建一个 RSS Feed阅读器
- 杭电 1176 免费馅饼 (数塔问题)
- recovery是什么意思?recovery功能详解刷机教程
- 关于win7 64位系统下安装ubuntu 64位系统记录
- VC 生成Dll 并使用