何时使用装饰图案? [英] When to Use the Decorator Pattern?
问题描述
我明白了这种模式,但我很想知道的是现实世界中时代的一些很好的具体例子,装饰图案是最佳/最优/优雅的解决方案。
谢谢。
装饰器模式在流中使用很多:您可以使用流包装流来获取附加功能。我已经看到了.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屋!