Decorator Pattern(装饰器)
来源:互联网 发布:淘宝怎么设置0.1元 编辑:程序博客网 时间:2024/05/29 17:49
/*Decorator Pattern个人理解:
* 装饰器模式系为了一些对象可以动态地增加功能,而避免过度使用继承,导致类膨胀的一种模式,简单的例子就是:
* 如果有牛奶,咖啡,糖,柠檬,那可以构成的饮料就有“加糖牛奶,不加糖加柠檬牛奶,加柠檬不加糖牛奶”等等诸如
* 此类的东西,如果利用继承去做的话,就会出现大量的继承类,如果不单单是糖,柠檬,而是有很多东西的话,这个类群可想而知
* 是多么庞大,所以就出现了利用Decorator Pattern去解决该问题。
* 其中有一个比较专业解释:
* Decorator Pattern――Attaches additional responsibilities to an object dynamically .
* Decorators provide a flexible alternative to subclassing for extending functionality .
*
* 其中Decorator Pattern 有几个重要成员:
* 1)抽象基类Component,暂时理解为统一的抽象基类,作为一个整体的抽象。
* 2)被装饰类ConcreteComponent,如上面例子所说的牛奶,咖啡等,都是被装饰的,如牛奶被“糖”或者“柠檬”“装饰”得到甜奶
* 3)装饰器抽象类Decorator,这个类是关键,具体来说就是该抽象类来装饰其他Component,其中一个特点是该类中有成员是Component
* 4)具体装饰类。
*
* 下面是一个Decorator Pattern的例子
* 其中milk coffee是被装饰对象,它们又继承了BaseDrink类,而BaseDrink类继承了Beverage(上面说的(Component抽象基类)
* 另外(seasoning调料类)等同于上面说的Decorator装饰器类,其中有一个成员是:Beverage pBe,说明它作用去装饰一个
* pBe。具体的装饰器有Lemon,Sugar等。
*UML图与 代码如下:(到具体情况下使用还没试过,有待实践)
*/
- Decorator Pattern(装饰器)
- 装饰器模式(Decorator Pattern)
- 7. Decorator pattern(装饰器模式)
- 装饰器模式(Decorator Pattern)
- 装饰器模式(Decorator Pattern)
- 装饰器模式(Decorator Pattern)
- Java Decorator Pattern(装饰器模式)
- 装饰模式Decorator Pattern
- 装饰模式(Decorator Pattern)
- 装饰模式(Decorator Pattern)
- 装饰模式--Decorator pattern
- 装饰模式 Decorator Pattern
- 装饰模式【DECORATOR PATTERN 】
- 装饰模式【Decorator Pattern】
- decorator pattern -- 装饰模式
- 装饰模式(Decorator Pattern)
- Decorator Pattern(装饰模式)
- 装饰模式-Decorator Pattern
- ORACLE存储过程----基本语法
- 在线运行代码框的代码
- 创意搜狗输入法设计理念
- Oracle JOB 用法小结
- reactos操作系统实现(26)
- Decorator Pattern(装饰器)
- 我写的读取ini文件的类
- 诚卖HP笔记本(意外年终抽奖抽中),并赠送神秘大礼包
- java.sql.SQLException: Statement parameter 1 not set.问题的解决
- rep 解释
- javascript闭包之悟(二)
- Struts 2.1发布
- Ubuntu下Java中文乱码解决
- 谈谈如何彻底卸载Oracle?