Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any design patterns used in the .NET Framework?

I would like to know: are any GoF design patterns are used in the .NET Framework?

BOUNTY:

I have seen the MSDN link below in an answer. Are there any post/video or can you can list patterns and most importantly WHERE it is used?

like image 668
Sandbox Avatar asked Aug 22 '09 19:08

Sandbox


People also ask

What design patterns are used throughout the .NET framework?

The . NET Framework uses the IEnumerable and IEnumerator interfaces to implement the Iterator pattern.

What are .NET design patterns?

Design Patterns in the object-oriented world is a reusable solution to common software design problems that occur repeatedly in real-world application development. It is a template or description of how to solve problems that can be used in many situations. "A pattern is a recurring solution to a problem in a context."

What is design pattern in framework?

Design patterns are smaller architectural elements than frameworks. A typical framework contains several design patterns, but the reverse is never true. Design patterns are less specialized than frameworks. Frameworks always have a particular application domain.

Which design patterns is used in Entity Framework?

Factory Method, an Entity Framework ObjectContext provides a CreateObjectSet<T> method, which creates an ObjectSet<T> for the given type. Since those object-sets are the main approach to access the entities within a context, I would say it is also a very important pattern used in EF.


1 Answers

The .NET framework uses many of the Gang of Four patterns. Here are just a few examples:

Creational patterns

  • Abstract Factory: System.Data.Common.DbProviderFactory. Every member function of this class is a factory method.
  • Builder: The WCF channel construction infrastructure.
  • Factory Method:
    • System.Data.IDbConnection.BeginTransaction(). The type of transaction created depends on the underlying IDbConnection implementation.
    • WebRequest.Create() returns a concrete type that depends on the URL scheme.
  • Prototype - used in framework for cloning and serialization
  • Singleton - used as an activation method in WCF, i.e. a web service may be treated as a singleton by the WCF infrastructure. Ditto for .NET Remoting.

Structural 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.
  • Composite: many examples
    • System.Windows.Forms.Control and its derived classes.
    • System.Web.UI.Control and its derived classes.
    • System.Xml.XmlNode and its derived classes.
  • Decorator:
    • System.Windows.Controls.Decorator (in WPF).
    • Some implementations of Stream are decorators around an inner stream (e.g. GZipStream, CryptoStream).
  • Facade: System.Xml.Serialization.XmlSerializer. XmlSerializer hides a complex task (that includes generating assemblies on the fly!) behind a very easy-to-use class.
  • Proxy: The web service proxies generated by svcutil.exe and deriving from System.ServiceModel.ClientBase<TChannel>

Behavioral 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: many examples
    • System.Collections.IEnumerable.
    • System.Collections.Generic.IEnumerable<T>.
    • System.Data.IDataReader.
  • Memento: The .NET Serializable pattern is a variation on the Memento pattern.
  • Observer - The .NET event mechanism.
  • Strategy - Sort method in ArrayList
  • Template Method - Render method for custom controls
  • Visitor : System.Linq.Expressions.ExpressionVisitor (used internally by [LINQ])
like image 200
Paul Lalonde Avatar answered Sep 20 '22 08:09

Paul Lalonde