This article is aimed at providing a brief idea of the design patterns & their types using C#, which is a list of Gang of Four design patterns. These patterns are considered as the best practices to write code & base of good software application architecture.

What is Design pattern ?

Software development includes tons of code writing. At last you get a product in your hand. But if the code is not written in proper well planned manner, then even a single requirement change in existing code, may turn your application upside down and it may involve lot of re-work in the existing code as well accommodating the required changes. Design patterns were introduced to help developer accommodate these kind of requirement changes and avoid waste of development efforts and of course time. So design patterns help by writing a clean, re-usable, decoupled and a well planned code.

What are Gang of four design patterns?

In .NET, these patterns are defined by group of four people generally referred as a group named Gang of Four or Go4. It is a group of 4 people who are author of the book named Design Patterns: Elements of Reusable Object-Oriented Software. They have explained 23 design patterns which are considered as the basis of writing a good quality code.

Types of gang of four patterns :

These patterns have been divide into 3 major categories, according to the of purpose these patterns solve. They are categorized as :

1. Structural patterns :

These type of patterns define the basic structure of the classes, in the application i.e how are they related to each other. A real world example can be an organization with different departments like HR, business development, technical departments etc. So, here the organization is divided into departments in the most efficient way possible and linked to each other as per the requirements of the organization. Technically speaking, the departments here play the role of the classes in our application code and these classes may be linked to each other somehow.

2. Creational patterns :

These type of patterns describe how the objects of the classes will be created, in the system. In terms of our real world example, it decides how new members are hired into the organization and added in the departments, as per the organization requirement. It is technically equivalent to creation of objects of the classes, as per the requirements of client code.

3. Behavioral patterns :

These type of patterns describe how the classes and the objects interact with each other, in the system. In our real world example, it could be described as the way different departments/members are interacting with each other. So in our example, these departments and their members are the classes and objects that interact with each other in the system. So they may be interacting through a pre-defined process or directly, as per the requirements.