Well,这几天在看O'Reilly的ActionScript 3.0 Design Patterns.英文版的说。主要还是,I'm sick of the translation edition.
不过看英文版的书,感觉很难进入脑子......So,take notes......
今天主题是“Decorator Pattern,装饰模式”的原理。
原文:The Decorator pattern addresses the issue of maintaining the structure while having
the ability to make changes by decorating the different components that make up the
application. The decorations are composed of descriptions and/or methods used to
wrap different objects in the application. As you will see, this design pattern allows
you to mix and match all the different components and decorations to optimize flexibility
and expandability, while core structure classes remain unaltered.
翻译:装饰模式强调,在保留程序原有结构的同时,通过装饰程序中的不同组件,来实现程序功能的更改。这些"装饰用品"由用于包装不同对象的说明和方法组成。正如你所看到的,装饰模式允许你通过混合使用不同的"组件"和"装饰",来优化程序的灵活性和延展性,同时程序的核心结构保持不变。
(1) 装饰对象和真实对象有相同的接口。这样客户端对象就可以以和真实对象相同的方式和装饰对象交互。
(2) 装饰对象包含一个真实对象的索引(reference)
(3) 装饰对象接受所有的来自客户端的请求。它把这些请求转发给真实的对象。
看图:
1.其中Component、Decorator两个类是抽象类。名字带有Concrete的都是派生类。
2.Component是Decorator的父类。
这样就是说,无论是Concrete Component抑或是Decorator和Concrete Decoration,这些类的父类(父父类)都是Component。
上面的图显示,一个Concrete Component被一个Concrete Decorator装饰后变成#1,之后又被装饰成#2、#3。而最终,#3仍然是一个Component类的实例。这样被装饰过的对象依然能被同一个变量所引用。
当你希望你的子类有各自的特性,并且不想通过修改父类实现的时候,就可以用装饰模式。
装饰模式使你能在不修改父类的情况下(即保持原程序设计不变),给子类添加不同的功能。
- 大小: 62.4 KB
- 大小: 23 KB
分享到:
相关推荐
vue脚手架 本框架已开发了所属相关组件,如有 定制组件 需求可联系
C#设计模式(12)-Decorator Pattern C#设计模式(11)-Composite Pattern C#设计模式(10)-Adapter Pattern C#设计模式(9)-Prototype Pattern C#设计模式(8)-Builder Pattern C#设计模式(7)-Singleton...
动态地给一个对象添加一些额外的职责。就扩展功能而言,它比生成子类方式更为灵活。
Nuxt属性装饰器 方便的ES / TypeScript装饰器,用于Nuxt中的类样式Vue组件(基于)以及(基于 )和Vuex(基于) 该库完全依赖于 。 执照 麻省理工学院执照 安装 安装非常容易 npm i -S nuxt-property-decorator ...
koa-swagger-decorator 使用装饰器自动生成swagger json文档 安装 npm install koa-swagger-decorator 贡献指南 请参考创建PR或发行前。 介绍 Koa Swagger装饰器 使用装饰器自动生成swagger json文档,添加对...
装饰者模式(Decorator Pattern)是一种结构型设计模式,它的定义是在不改变原有对象结构的基础上,动态地给该对象增加一些职责(即增加其额外功能)。这种模式允许向一个现有的对象添加新的功能,同时又不改变其...
前端开源库-pure-render-decorator纯渲染装饰,使反应组件纯。
@ redtea / craco-parameter-decorator 这个插件将为您的项目设置 。 支持: create-react-app:3.x,4.x craco:5.x,6.x :hammer_and_wrench: 安装 纱 $ yarn add -E @redtea/craco-parameter-decorator NPM...
Head First 设计模式 (三) 装饰者模式(decorator pattern) C++实现 VS2012 下通过
官方离线安装包,亲测可用
树形结构的处理——组合模式(二) 树形结构的处理——组合模式(三) 树形结构的处理——组合模式(四) 树形结构的处理——组合模式(五) 装饰模式-Decorator Pattern 扩展系统功能——装饰模式(一) 扩展系统...
NULL 博文链接:https://janeky.iteye.com/blog/472502
它比React组件的core-decorator绑定装饰器更轻巧,更快。安装npm install react - bind - decorator -- save用法: import reactbind from 'react-bind-decorator' ;@ reactbind ( )class Foo extends React . ...
eslint插件使用装饰器 这是eslint的自定义插件,可在方法上强制使用装饰器。 注意 这仅适用于@typescript-eslint插件 安装 npm install --save-dev eslint-plugin-use-decorator 用法 将此添加到您的.eslintrc // ...
离线安装包,亲测可用
c++设计模式-结构型模式-装饰器模式;QT工程;c++简单源码; 装饰器(Decorator)模式的定义:指在不改变现有对象结构的情况下,动态地给该对象增加一些职责(即增加其额外功能)的模式,它属于对象结构型模式。
NULL 博文链接:https://tcg.iteye.com/blog/1283190
eslint-plugin-decorator-position 一个ESlint插件,它提供一组规则以强制一致的装饰器位置 :red_exclamation_mark: 要求 >= 5 >= 8.5 :rocket: 用法1.安装插件yarn add --dev eslint-plugin-decorator-position ...
java-io-decorator.pdf