哪些是C#本机内置设计模式?
无论框架版本如何,C#都支持哪些设计模式? 我正在考虑可以在接口IObservable中找到的Observer模式等模式。 ObservableCollection,INotifyPropertyChanged等。
请在答案中提供模式的命名空间!
Action
(通常用作访客模式)
发现您已经在.NET Framework中使用的设计模式 ( MSDN Magazine
)
例
public class Root { //Private and not exposed in a IList property = Encapsulation private List _nodes = new List (); public void Visit(Action visitor) { // Controlled enumeration, can for instance handle exceptions in here. foreach (var item in _nodes) { visitor(node); } } } // usage root.Visit(node => Console.WriteLine(node));
创作模式
抽象工厂
- System.Data.Common.DbProviderFactory
生成器
- System.Text.StringBuilder
- System.Data.Common.DbConnectionStringBuilder
工厂方法
- System.Activator
- System.Net.WebRequest
原型
- System.ICloneable
独生子
- System.StringComparer.InvariantCulture
- System.StringComparer.InvariantCultureIgnoreCase
结构模式
适配器
- 就是System.IO.StreamReader
桥
- System.Globalization.CultureInfo
综合
- System.ComponentModel.IComponent
装饰
- System.IO.Stream
正面
- 统环境
- System.String
飞锤
- System.StringComparer
代理
- System.Net.WebClient
- System.Runtime.Remoting.Proxies.RealProxy
- System.ServiceModel.ICommunicationObject
行为模式
责任链
- Microsoft.Practices.EnterpriseLibrary.Logging.Logger
命令
- System.Windows.RoutedEventArgs
翻译员
- System.IFormatProvider
- System.Text.RegularExpressions.Regex
迭代器
- System.Collections.IEnumerable
- System.Data.IDataReader
中间人
- System.Threading.Timer
纪念品
- System.Runtime.Serialization.ISerializable
观察
- System.EventHandler
- System.IObservable
州
- ??
战略
- System.Collections.Generic.IComparer
模板方法
- System.Web.UI.Page
游客
- System.Linq.Expressions.ExpressionVisitor
Iterator是一个(所有集合类和数组都可以使用foreach
语句进行迭代)。
另一个是观察者模式 – 这就是事件的本质。 在4.0中,添加了IObservable和ObservableCollection。
StringBuilder使用构建器设计模式..
还有DbDataAdapter类(适配器模式)。
Null对象模式也被广泛使用。
抽象工厂: System.Data.Common.DbProviderFactory
观察者模式。 我们所有的事件和代表都是通过观察者模式提出的。
工厂模式。 工厂的连接字符串和数据库提供程序
迭代器模式:我们的foreach语句中的Ienumerable,Ienumerators
适配器:COM通信。 运行时可调用包装程序(RCW)
模板:在ASP.NET类中的几个地方使用esp,您可以在其中覆盖以提供新的实现
代理:对于我们所有的webservice调用。 在c#3.0中,我们也获得了代理集合。
还有更多。 但这些是我想到的
委托模式(代表和表达的内容)
代理模式经常使用。