装饰者模式
来源:互联网 发布:香港专业教育学院 知乎 编辑:程序博客网 时间:2024/05/17 02:25
1、定义
动态的给对象添加一些额外的职责。从扩展功能角度来讲,相对于通过继承生成子类,此方式更为灵活。
2、实例
Java I/O流:InputStream、OutputStream、Reader、Writer
分析InputStream
抽象构件(Component)角色:由InputStream扮演。这是一个抽象类,为各种子类型处理器提供统一的接口。
具体构件(Concrete Component)角色:由ByteArrayInputStream、FileInputStream、PipedInputStream以及StringBufferInputStream等扮演,它们实现了抽象构建角色所规定的接口。
抽象装饰(Decorator)角色:由FilterInputStream扮演。它实现了InputStream所规定的接口。
具体装饰(Concrete Decorator)角色:由DateInputStream、BufferedInputStream 以及两个不常用到的类LineNumberInputStream和PushbackInputStream扮演。
BufferedInputStream “装饰” 了InputStream的内部工作方式,使得流的读入操作使用缓冲机制。
LineNumberInputStream和PushbackInputStream也同样“装饰”了InputStream的内部工作方式, 前者使得程序能够按照行号读入数据;后者能使程序在读入的过程中退后一个字符。
DateInputStream子类读入各种不同的原始数据类型以及String类型的数据。
- 装饰者模式(Derector)
- 装饰者模式
- Decorator 装饰者模式
- 装饰者设计模式
- 装饰者模式
- 装饰者模式
- 装饰者模式
- 装饰者模式(Decorator)
- 装饰者模式
- 装饰者模式
- 装饰者模式
- 装饰者模式 DecoratorPattern
- 设计模式 - 装饰者
- 装饰者模式
- 装饰者模式
- 装饰者模式 - 2
- 装饰者模式
- 装饰者模式
- 排序算法总结与代码实现
- 611. Valid Triangle Number
- xpath小练习
- Codeforces #269 (Div. 2)D. MUH and Cube Walls(KMP)
- Leetcode算法学习日志-338 Counting Bits
- 装饰者模式
- 抽象类,接口,与类的关系
- bzoj 2346: [Baltic 2011]Lamp spfa
- sqlyog注册码
- 大数据预科班3
- Atcoder Together
- 数据类型 数据类型转换 运算符
- 【NOIP2015D2】 解题报告
- 用GridView展示已经安装的应用