扩展方法 - 装饰模式 [英] Extension Methods - Decorator Pattern

查看:110
本文介绍了扩展方法 - 装饰模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我们是否可以将扩展方法作为C#中的装饰器模式的实现来考虑?因为目标是一样的,但实施的逻辑和概念可能会有所不同?



谢谢!

解决方案

装饰器模式通常与添加相关联一种类型的特定实例的行为与其他实例无关。在扩展方法的情况下,它会影响在同一范围内编译的类型的所有实例。我认为它不是装饰图案的一部分。


I was wondering if we can consider extension methods as an implementation of the decorator pattern in C#? as the aim is the same but logic of implementation as well as the conception may differ?

Thanks!

解决方案

The decorator pattern is usually associated with adding behavior to particular instances of a type independently of other instances. In the case of an extension method it affects all instances of a type which are compiled in the same scope. I'd argue that it's not a part of the decorator pattern.

这篇关于扩展方法 - 装饰模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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