Gang of four patterns Design patterns using C#

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.

Following are the patterns defined under this category :

1. Adapter                           2. Bridge                  3. Composite

4. Decorator Pattern           5.  Facade                6. Flyweight           7. Proxy

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.

Following are the patterns under this category :

1. Abstract  Factory             2. Builder                3. Factory Method

4. Prototype                         5.  Singleton

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.

Following are the patterns defined under this category :

1. Chain of Responsibility      2. Observer     3. State      4. Strategy             5. Mediator

6. Command       7.  Interpreter        8. Visitor          9. Iterator              10. Memento

11. Template

So we will be covering these patterns one by one, in further posts. Hope you guys enjoy reading these.

Reference Links :

About Jasminder

.Net developer and blogger by profession, keen to learn new technologies, love nature, music and cricket.
This entry was posted in Design Patterns and tagged . Bookmark the permalink.

I have a suggestion..

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s