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?
The . NET Framework uses the IEnumerable and IEnumerator interfaces to implement the Iterator pattern.
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."
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.
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.
The .NET framework uses many of the Gang of Four patterns. Here are just a few examples:
Creational patterns
System.Data.Common.DbProviderFactory
. Every member function of this class is a 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.Structural patterns
System.Data.SqlClient.SqlConnection
, System.Data.OleDb.OleDbConnection
etc. Each provider is an adapter for its specific database.System.Windows.Forms.Control
and its derived classes.System.Web.UI.Control
and its derived classes.System.Xml.XmlNode
and its derived classes.System.Windows.Controls.Decorator
(in WPF).Stream
are decorators around an inner stream (e.g. GZipStream
, CryptoStream
).System.Xml.Serialization.XmlSerializer
. XmlSerializer hides a complex task (that includes generating assemblies on the fly!) behind a very easy-to-use class.System.ServiceModel.ClientBase<TChannel>
Behavioral Patterns
System.Web.UI.Control.OnBubbleEvent()
and System.Web.UI.Control.RaiseBubbleEvent()
. System.Windows.Input.ICommand
(in WPF).System.Linq.Expressions.Expression
and related classes.System.Collections.IEnumerable
.System.Collections.Generic.IEnumerable<T>
.System.Data.IDataReader
. System.Linq.Expressions.ExpressionVisitor
(used internally by [LINQ])If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With