Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which are C# native built-in design patterns?

Which design patterns are build-in supported by C# regardless framework version? I'm thinking of patterns such as Observer pattern that can be found in interface IObservable. ObservableCollection, INotifyPropertyChanged etc.

Please provide with the namespace of the pattern in your answers!

like image 280
Amir Rezaei Avatar asked Oct 28 '10 08:10

Amir Rezaei


People also ask

What are identifiers C?

"Identifiers" or "symbols" are the names you supply for variables, types, functions, and labels in your program. Identifier names must differ in spelling and case from any keywords. You cannot use keywords (either C or Microsoft) as identifiers; they are reserved for special use.

What does || mean in C?

The logical OR operator ( || ) returns the boolean value true if either or both operands is true and returns false otherwise.

Which are logical operators in C?

Types of Logical Operators in C We have three major logical operators in the C language: Logical NOT (!) Logical OR (||) Logical AND (&&)


2 Answers

Action<T> (normally used as visitor pattern)

Discover the Design Patterns You're Already Using in the .NET Framework (MSDN Magazine)

Example

public class Root {     //Private and not exposed in a IList property = Encapsulation     private List<Node> _nodes = new List<Node>();       public void Accept(Action<Node> visitor)     {         // Controlled enumeration, can for instance handle exceptions in here.         foreach (var item in _nodes)         {             visitor(node);         }     } }  // usage root.Accept(node => Console.WriteLine(node)); 
like image 175
jgauffin Avatar answered Oct 19 '22 12:10

jgauffin


Creational Patterns

Abstract Factory

  • System.Data.Common.DbProviderFactory

Builder

  • System.Text.StringBuilder
  • System.Data.Common.DbConnectionStringBuilder

Factory Method

  • System.Activator
  • System.Net.WebRequest

Prototype

  • System.ICloneable

Singleton

  • System.StringComparer.InvariantCulture
  • System.StringComparer.InvariantCultureIgnoreCase

Structural Patterns

Adapter

  • System.IO.StreamReader

Bridge

  • System.Globalization.CultureInfo

Composite

  • System.ComponentModel.IComponent

Decorator

  • System.IO.Stream

Facade

  • System.Environment
  • System.String

Flyweight

  • System.StringComparer

Proxy

  • System.Net.WebClient
  • System.Runtime.Remoting.Proxies.RealProxy
  • System.ServiceModel.ICommunicationObject

Behavioral Patterns

Chain Of Responsibility

  • Microsoft.Practices.EnterpriseLibrary.Logging.Logger

Command

  • System.Windows.RoutedEventArgs

Interpreter

  • System.IFormatProvider
  • System.Text.RegularExpressions.Regex

Iterator

  • System.Collections.IEnumerable
  • System.Data.IDataReader

Mediator

  • System.Threading.Timer

Memento

  • System.Runtime.Serialization.ISerializable

Observer

  • System.EventHandler
  • System.IObservable

State

  • ??

Strategy

  • System.Collections.Generic.IComparer

Template Method

  • System.Web.UI.Page

Visitor

  • System.Linq.Expressions.ExpressionVisitor
like image 27
Shinji Nishizono Avatar answered Oct 19 '22 11:10

Shinji Nishizono