“Decorator的招供”,用采访的方式讨论了Decorator模式的缺点,这本书中处处都是这种恰当的拟人写法。
HeadFirst: Welcome Decorator Pattern. We’ve heard that you’ve been a bit down on yourself lately?
Decorator: Yes, I know the world sees me as the glamorous design pattern, but you know, I’ve got my share of problems just like everyone.
HeadFirst: Can you perhaps share some of your troubles with us?
Decorator: Sure. Well, you know
I’ve got the power to add flexibility to designs, that much is for
sure, but I also have a dark side. You see, I can sometimes add a lot
of small classes to a design and this occasionally results in a design
that’s less than straightforward for others to understand.
HeadFirst: Can you give us an example?
Decorator: Take the Java I/O
libraries. These are notoriously difficult for people to understand at
first. But if they just saw the classes as a set of wrappers around an
InputStream, life would be much easier.
HeadFirst: That doesn’t sound so bad. You’re still a great pattern, and improving this is just a matter of public education, right?
Decorator: There’s more, I’m
afraid. I’ve got typing problems: you see, people sometimes take a
piece of client code that relies on specific types and introduce
decorators without thinking through everything. Now, one great thing
about me is that you can usually insert decorators transparently and
the client never has to know it’s dealing with a decorator. But like I
said, some code is dependent on specific types and when you start
introducing decorators, boom! Bad things happen.
HeadFirst: Well, I think
everyone understands that you have to be careful when inserting
decorators, I don’t think this is a reason to be too down on yourself.
Decorator: I know, I try not to
be. I also have the problem that introducing decorators can increase
the complexity of the code needed to instantiate the component. Once
you’ve got decorators, you’ve got to not only instantiate the
component, but also wrap it with who knows how many decorators.
HeadFirst: I’ll be interviewing the Factory and Builder patterns next week – I hear they can be very helpful with this?
Decorator: That’s true; I should talk to those guys more often.
HeadFirst: Well, we all think
you’re a great pattern for creating flexible designs and staying true
to the Open-Closed Principle, so keep your chin up and think positively!
Decorator: I’ll do my best, thank you
分享到:
相关推荐
iOS快速样板 应用程序在iOS应用程序中以快速方式实现架构,并在MVVM中使用Swinject和RxSwift。 入门 在样例文件中添加Rubygen.rb,在新对象上创建永久性副本,在每个样例中都添加了示例... -f Forza gli input di confe
ApiRTC 该存储库包含用于将ApiRTC集成到Web应用程序中的实时通信的示例。 ApiRTC是WebRTC PaaS(平台即服务),可简化开发人员对WebRTC技术的访问。 使用我们的API,只需几行代码即可向您的网站和移动应用... Confe
CVPR2020:如何训练您的深度多对象跟踪器 新闻... Yihong and Osep, Aljosa and Ban, Yutong and Horaud, Radu and Leal-Taix{\'e}, Laura and Alameda-Pineda, Xavier}, booktitle={Proceedings of the IEEE/CVF Confe
Conference Calendar CONFERENCE CALENDAR Conference Calendar International Gene Therapy Meetings 2001 ...Gene Vector Production Network Conference October 4–5, Genocentre, Evry, France... Siebens Confe
Conference Calendar CONFERENCE CALENDAR Conference Calendar International Gene Therapy Meetings 2001 ...Gene Vector Production Network Conference October 4–5, Genocentre, Evry, France... Siebens Confe
3. 在 `.vimrc` 文件中进行所需的修改,然后使用 `:wq` 保存并关闭这个窗口。 4. 回到原来的文件窗口,再次按 `Esc`。 5. 现在输入 `:so $MYVIMRC` 或 `:source ~/.vimrc`,这将从当前的 `.vimrc` 文件加载新的设置...
尖峰网络的基于事件的角速度回归 这是Mathias Gehrig,Sumit Bam Shrestha,Daniel Mouritzen和的论文《基于事件的带有尖峰网络的角速度回归》的代码。... journal = { {IEEE} International Confe
诊断时间动作检测器(DETAD)中的错误该存储库旨在承载用于分析时间动作本地化算法的诊断工具。 它包括三个分析:假阳性分析,定位度量敏感性分析和假... Victor and Ghanem, Bernard}, booktitle={The European Confe
pyGeo pyGeo是面向对象的几何处理框架,用于多学科设计优化。 它提供了基于自由变形(FFD)的几何处理对象,与NASA的Vehicle Sketch Pad几何引擎的接口,简单的几何约束公式化对象以及一些用于几何处理的实用... @confe