Design Patterns in C#

Design Patterns provides the standard, efficient and reusable solution for the common software design problems that you face several times in your daily coding practices. Design pattern is about re-usability of code or design and how object should interact with each other. This article provides implementation of commonly used design patterns in C#.

There are several design pattern available and you should choose right pattern to solve your problem. You can also write a custom design pattern that will solve some standard design problem.

Gang of Four Design Patterns in C#

Gang of Four (GoF) design pattern are considered as the foundation of design patterns. This page provides tutorials onĀ Gang of Four design patterns. The examples are explained in C# language in .NET environment.

Gang of Four Design Pattern is divided in three categories – creational, structural and behavior.

Creational Design Pattern

  • Factory Method: Solves problem of creating objects
  • Abstract Factory: Solves problem of creating related objects
  • Builder: Separates construction of complex object from its representation
  • Prototype: Duplicates the given object.
  • Singleton: Ensures a single instance of a class.

Structural Design Pattern

  • Adapter: Provides interface to interact between mutually incompatible classes
  • Bridge: Decouples implementation of a class from abstraction
  • Decorator: Adds additional functionality to an already existing objects
  • Facade: Provides abstracted view of an complex system.
  • Flyweight: Allows sharing of similar type of objects.
  • Proxy: Provides proxy class that will represent actual class functionalities.
  • Composite: Sets up objects into the tree structure to represent part-whole hierarchy.

Behavioral Design Pattern

  • Chain of Responsibility: Handles a request by different handlers in sequence
  • Command: An object stores all the required information that is used to perform some task.
  • Strategy: Provides a set of algorithm to choose to perform some operation.
  • Template Method: Provides the skeleton to an algorithm that can be overridden by other class
  • Observer: Provides notification to the subscriber from the publisher object.
  • Iterator
  • Interpreter
  • Mediator: solves the problem around the interaction between a set of objects.
  • Memento: Stores the internal state of an application that can be restored later.
  • State: Allows an object to change the behavior when its internal state changes.
  • Visitor

I hope you enjoyed reading implementation of design patterns in C#. Please post your comments for feedback and queries. Thanks for reading.

The following two tabs change content below.
Gyanendu Shekhar is a technology enthusiast. He loves to learn new technologies. His area of interest includes Microsoft technologies, Augmented reality, Virtual reality, unity3d and android development.