mardi 30 décembre 2014

Examples of Design Patterns used in .Net Framework [on hold]

I wondered whether it's possible to gather example for each of GoF patterns in .NET Framework?


(not just examples of the patterns on C# like it's at http://www.dofactory.com/) but implementation in .NET Framework types


Can anyone remember examples of usages in .Net Framework of the following patterns:



  • Bridge

  • Flightweight

  • Mediator

  • State


I summarized material from similar questions on stack overflow:



  1. examples in .NET framework of Observer Iterator Decorator Adapter Factory Strategy Composite Template Method patterns

  2. examples in .NET framework of Observer Iterator Decorator Adapter Factory Strategy Composite Template Method, Patterns in the ASP.NET Pipeline, Intercepting Filter Pattern, Page Controller Pattern

  3. examples in .NET framework of Factory Method Singleton Prototype Adapter Composite Decorator Proxy Observer Iterator

  4. similar question - Are there any design patterns used in the .NET Framework? thanks Paul Lalonde and Peter Mortensen for their comment with examples for many usages of GoF patters


Creational patterns



  • Abstract Factory: System.Data.Common.DbProviderFactory. Every member function of this class is a factory method.

  • Builder: The WCF channel construction infrastructure or SqlCommandBuilder and StringBuilder

  • Factory Method System.Data.IDbConnection.BeginTransaction(). The type of transaction created depends on the underlying IDbConnection implementation or WebRequest (HttpWebRequest/FtpWebRequest)

  • Singleton - in .NET Remoting

  • Prototype - cloning and serialization


Behavioral patterns



  • Adapter: The ADO.NET providers, eg System.Data.SqlClient.SqlConnection, System.Data.OleDb.OleDbConnection etc. Each provider is an adapter for its specific database.

  • Bridge - ?

  • Composite:

    • System.Windows.Forms.Control and its derived classes.

    • System.Web.UI.Control and its derived classes.

    • System.Xml.XmlNode and its derived classes.



  • Decorator: Stream (FileStream/NetworkStream etc.)

  • Facade: System.Xml.Serialization.XmlSerializer. XmlSerializer hides a complex task (that includes generating assemblies on the fly!) behind a very easy-to-use class.

  • Flightweight -?

  • Proxy: The web service proxies generated by svcutil.exe and deriving from System.ServiceModel.ClientBase<TChannel>


Structural Patterns



  • Chain of responsibility: System.Web.UI.Control.OnBubbleEvent() and System.Web.UI.Control.RaiseBubbleEvent().

  • Command:System.Windows.Input.ICommand (in WPF).

  • Interpreter: System.Linq.Expressions.Expression and related classes.

  • Iterator - called "enumerator" and represented by the IEnumerator interface

  • Mediator -?

  • Memento: System.Linq.Expressions.Expression and related classes.

  • Observer - delegates and events ex. Button control and Click event

  • State- -?

  • Strategy - Sort method in ArrayList

  • Template Method - Render method for custom controls

  • Visitor : System.Linq.Expressions.ExpressionVisitor (used internally by [LINQ])


Aucun commentaire:

Enregistrer un commentaire