Bhaweshdeepak
Design Pattern in C#
2 min readMar 21, 2021

--

The design principle is a concept that is used to make your application more reliable, Scalable, and Maintainable.

The design pattern was introduced by four authors called Gang of Four in his book “Elements of Reusable Object-Oriented Software”.

Hence design pattern is nothing but documented and tested solution for a recurring problem that comes in our application context.

There are three types of design pattern

  1. Creational Design Pattern,
  2. Structural Design Pattern
  3. Behaviour Design Pattern

Creational Design Pattern: It deals with object creation logic for our application. The Creational design pattern centralized the object creation logic to one place.

Why Required Creational Design Pattern

Let suppose we have a very large application, and we have a lot of modules (Like HR Module, Product Module, Inventory Module, Employee Module)present in our Application. It means there is a large number of classes present in our application, and we need to create a lot of objects on the client-side. And the object creation logic is scattered throughout the client application, which makes our application complicated and bulky. To resolve this issue we need to use the Creational Design Pattern.

Hence as a developer, we need to decide which object need to create in the given case.

The Creational design Pattern

  1. SingleTon Desing Pattern
  2. Factory Design Pattern
  3. Abstract Factory Design Pattern
  4. Builder Design Pattern
  5. Fluent Interface Design Pattern
  6. Prototype Design Pattern (Shallow and Deep copy design Patter)
  7. Factory Method Design Pattern

Structural Design Pattern: The Structural Design Pattern is used to help the problem which comes when we change the structure of the class.

Let Suppose we have the class Employee and another class Salary which calculates the salary of the employee. The Employee class used the Salary class, To calculate the salary of each and every employee. But Some time later we want to remove the Salary class from the employee class, Hence we have to change the structure of the Employee class, this change should not affect the whole application. To resolve these type of issue we use the structural design pattern

  1. Adapter Desing Pattern
  2. Facade Design Pattern
  3. Decorator Design Pattern
  4. Composite Design Pattern
  5. Proxy Design Pattern
  6. Flyweight Desing Pattern
  7. Bridge Design Pattern

Behaviour Design Pattern :

When we change the behaviour of the class, then we do not want this will affect the complete project. So we have to use the Behaviour Design pattern.

Let Suppose that we have a class Salary that calculates the Employee Salary, The bonus of Employee Salary will be credited when he works more than 72 hours a week. But some time later the HR will change the policy and increase the working hour to 90, Hence we need to change the method which calculates the employee salary(Change the behaviour of the class). This change should not affect the complete project.

  1. Chain of Responsibility
  2. Command
  3. Observer
  4. Iterator
  5. State
  6. Template Method
  7. Visitor
  8. Strategy
  9. Mediator
  10. Momento
  11. Interpreter Design Pattern

--

--