何时使用装饰图案? [英] When to Use the Decorator Pattern?

查看:116
本文介绍了何时使用装饰图案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究我的设计模式,而我还没有认真使用我的编码模式就是装饰模式。



我明白了这种模式,但我很想知道的是现实世界中时代的一些很好的具体例子,装饰图案是最佳/最优/优雅的解决方案。



谢谢。

解决方案

div>

装饰器模式在流中使用很多:您可以使用流包装流来获取附加功能。我已经看到了.Net框架 - 据我所知,这发生在别的地方。我最喜欢的是在FileStream周围使用GZipStream,用于添加压缩​​。


I am going over my design patterns, and one pattern I have yet to seriously use in my coding is the Decorator Pattern.

I understand the pattern, but what I would love to know are some good concrete examples of times in the real world that the decorator pattern is the best/optimal/elegant solution. Specific situations where the need for the decorator pattern is really handy.

Thanks.

解决方案

The decorator pattern is used a lot with streams: you can wrap a stream with a stream to get added functionality. I've seen this with the .Net framework - as far as I know this occurs elsewhere. My favourite is using GZipStream around a FileStream, for added compression.

这篇关于何时使用装饰图案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆