Design Pattern articles in this series are listed below:
Design Patterns - An Overview
Design Patterns – Using the Strategy Pattern in C#
Design Patterns – Using the Singleton Pattern in C#
Design Patterns – Using the Adapter Pattern in C#
Design Patterns - Using the Facade Pattern in C#
Design Patterns - Using the Composite Pattern in C#
Design Patterns - Using the Decorator Pattern in C#
Design Patterns - Using the Abstract Factory Pattern in C#
Design Patterns – Using the Builder Pattern in C#
Design Patterns - Using the Observer Pattern in C# (Events and Delegates)
Design Patterns – Using the Chain of Responsibility Pattern in C#
Design Patterns – Using the State Pattern in C#
Design Patterns – Which to use When? Take the Quiz!
This is the first post in the series of Design Patterns. Stay tuned for more design pattern related articles in the future. Let’s start by defining Design Patterns.
Wikipedia defines Design Patterns as
“design pattern is a general reusable solution to a commonly occurring problem in software design”
Design patterns are language independent mechanisms for providing solutions to common problems. Adhering to design patterns help in creating systems that are robust, scalable and maintainable as design patterns follow best practices and established standards. Design patterns have existed in non software engineering disciplines for a long time. Mechanical engineers reuse proven standard design models when designing a new kind of lathe machine. Instead, they reuse existing designs.
In real world, using design patterns is a 2 step approach.
1. Understanding different types of design patterns
There are a lot of books and articles online that are written about design patterns. Developers who are interested in using design patterns first need to get an understanding of different design patterns. Some of my favorite resources are:
- Wikipedia
- DoFactory.com
- Orielly C# 3.0 Design Patterns
2. Determining what design pattern to use
Once you have an understanding on different types of design patterns, the next question is when to use them and which one to use. Unfortunately, there is no rule of thumb. This is more of an art that is gained from practical experience. Developers should not chose a design pattern and design a solution around it. Instead they need to analyze at a higher level, the problem they are attempting to solve. It then makes it easier to map the problem at hand to different design patterns. Once you know the patterns, they become tools in your toolbox. By experience, the tool to choose for a particular task becomes intuitive (similar to choosing a hammer without a second thought for hitting a nail to a wall)
History of Design Patterns
Design Patterns were first introduced in the late 1980s. However, they did not gain popularity until the book “Design Patterns: Elements of Reusable Object-Oriented Software” was published by four authors - Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides in 1994. The four authors are known as Gang of Four. The patterns they published are known as GoF Patterns.
There are a total of 23 classic design patterns
Types of Design Patterns
Design Patterns can be broadly classified into 3 structural groups:
1. Structural Patterns: These are design patterns that are used to define structures of objects and classes that can work together
2. Behavioral Patterns: These are design patterns that are concerned with algorithms and communications between them
3. Creational Patterns: These are design patterns that aim to encapsulate and hide the object instantiation logic. They help in increasing the system’s flexibility in how/when/who of object creation
The popular design patterns are illustrated in the figure below.
In future posts, we will explain different design patterns with examples in C#. Until then, check out other posts on this website and do not forget to subscribe to the RSS feed!