Design Patterns in C# With Real-Time Examples

Design Patterns in Csharp

In this article series, I am going to cover all the basic and advanced concepts of design patterns in csharp using ASP.NET MVC by taking some real-time scenarios.

It is very easy to Implement design patterns in the applications. Writing the code aligning with design patterns will make your applications Reliable, Scalable and Maintainable.

What are Design Patterns in csharp?

Design patterns are reusable solutions to the problems that we encounter in our day to day programming. Design Patterns are basically used to solve the problems of object generation and integration. In other words, Design patterns act as the templates which can be applied to the real-world programming problems.

For whom:

These tutorials are design for beginners as well as professionals who want to learn Design Pattern step by step from very basics to the advanced concepts of Design Pattern. This tutorial provides a hands-on approach to the subject with step-by-step programming examples that will assist you to learn and put the acquired knowledge into practice.

History and evolution of design Patterns

The four authors of the book famously know as Gang of four is the ones who brought the concepts of design patterns in their book “Elements of Reusable Object-Oriented software”.

Gang of Four has divided the book into two parts with first part explaining the pros and cons of object-oriented programming and the second part describes the evolution of 23 classic software design patterns.

For more details, please refer to the following Wikipedia article

https://en.wikipedia.org/wiki/Design_Patterns

Types of Design Patterns

Gang of Four categorized the design patterns into 3 types based on different problems encountered in the real world applications. They are Creational, Structural and Behavioral.

Creational design patterns:

As the name says these design patterns deal with the object creation and initialization. Creational design pattern gives the programmer more flexibility in deciding which objects need to be created for a given case.

Examples of Creational design patterns category: Singleton, Factory, Builder, Prototype and Abstract Factory etc.

Structural design patterns: 

These design patterns deal with the relationships between the entities i.e. class and object. In simple words, this pattern focuses on decoupling interface, implementation of classes and its objects.

Examples of Structural design patterns category: Adapter, Facade, and Bridge etc.

Behavioral design patterns: 

These patterns deal with communication between Classes and objects.

Examples of Behavioral design patterns: Chain of Responsibility, Command, and Interpreter etc.

For understanding Csharp Design Patterns better it is very important to have basic knowledge about the following object-oriented concepts

  1. Abstraction
  2. Inheritance
  3. Polymorphism
  4. Encapsulation
  5. Interfaces
  6. Classes
  7. Abstract classes