装饰模式简介(Brief Introduction)
来源:互联网 发布:天下3张凯枫捏脸数据 编辑:程序博客网 时间:2024/06/01 10:26
一、装饰模式简介(Brief Introduction)
动态地给一个对象添加一些额外的职责。
优点:把类中的装饰功能从类中搬移出去,这样可以简化原有的类。有效地把类的核心功能和装饰功能区分开了。
二、解决的问题(What To Solve)
已经开发完毕的对象,后期由于业务需要,对旧的对象需要扩展特别多的功能,这时候使用给对象动态地添加新的状态或者行为(即装饰模式)方法,而不是使用子类静态继承。
比如,刚买一辆汽车如下图
此汽车不符合你的个性要求,比如外表不够美观,发动机马力不足,不能满足你的速度激情,于是你需要对汽车的外表进行装饰,同时需要提高发动机的性能。这些操作通过装饰模式就能很好地解决问题。最终得到如下图所示的个性汽车。
三、装饰模式分析(Analysis)
1、装饰模式结构
Component定义了一个对象接口,可以给这些对象动态地添加职责。
ComcreteComponent定了一个具体的对象,也可以给这个具体的对象添加职责。
Decorator抽象装饰类,继承了Component对象接口,从外类扩展Component类的功能,但对于Component
- 装饰模式简介(Brief Introduction)
- 适配器模式简介(Brief Introduction)
- 状态模式简介(Brief Introduction)
- 时序图简介(Brief introduction)
- Brief Introduction
- IoC 简介:A Brief Introduction to IoC[读后感]
- [机器学习入门] 李弘毅机器学习笔记-7 (Brief Introduction of Deep Learning;深度学习简介)
- BIO socket -- brief introduction
- scala brief introduction
- SDN Brief Introduction
- Differential Privacy brief introduction
- 装饰模式简介
- 装饰模式(Decorator)简介
- 装饰模式简介
- 装饰模式简介
- Data Structures and algorithm analysis—1.3. A Brief Introduction to Recursion(数据结构—1.3 递归的简介)(之一)
- Data Structures and algorithm analysis—1.3. A Brief Introduction to Recursion(数据结构—1.3 递归的简介)(之二)
- 3G Mobility Management brief introduction
- 基于Hemlock的ejabberd ActionScript游戏客户端开发
- 命令(Command)模式
- 状态模式
- 栈应用——分隔符匹配
- Android AlarmClock 闹钟应用 简单分析
- 装饰模式简介(Brief Introduction)
- 从printf谈可变参数函数的实现
- 状态模式简介(Brief Introduction)
- Net设计模式实例之桥接模式( Bridge Pattern)
- 从printf谈可变参数函数的实现
- MySQLdb disables autocommit by default
- Test.code
- java多线程学习
- this is my first blog.