Nearly every software developer is familiar with the term "Design Patterns".
This article is the beginning of a new series called "Lean Design Patterns with C#".
This article is all about the basics of Design Patterns like what they are and why are they required.
Problem Statement
Consider a scenario consisting of 3 people, such as:
All of them have the same goal, which is to travel to Location W.
And each of them used their own strategies to do it. But later they discovered how extremely expensive plane tickets are. A Train however is not as convenient, since we must change trains thrice, and the Bus will take 18 hours.
In short, I was trying to explain for you that for every problem and solution there are new problems.
So what do we need? We need a strategy which is tested, proven, documented and ready to implement.
In this case we need someone who has been in Location W before, on whom all three have trust.
What are Design Patterns?
- Design Patterns are widely accepted, recurring or reusable solutions to the problems occurring again and again in software development.
- A Design pattern is not a final product; instead it's a template or we can say a design which can be transformed into code.
- They are nothing but best practices.
- They speed up the development process by providing tested and proven development paradigms.
- It's not like we should always use Design Patterns. Decisions such as whether a design pattern is needed or not and which design pattern to use and such depends completely on the problem context.
Categories of Design Patterns
Creational Patterns
We use the "new" keyword whenever we want to create a new object and creational patterns solve problems related to the creation of objects.
They are:
- Singleton
- Factory
- Abstract Factory
- Builder
- Prototype
Structural Patterns
Sometimes we encounter a point where we want to change the structure of the class without affecting the project. A structural pattern rescues us in these situations.
They are:
- Adapter
- Bridge
- Composite
- Decorator
- Facade
- Flyweight
- Proxy
Behavioral Patterns
A behavioral pattern solves problems occurring when we try to tamper with the behavior of a class.
They are:
- COR (Chain of Responsibility)
- Command
- Interpreter
- Iterator
- Mediator
- Memento
- Observer
- State
- Strategy,
- Template Method
- Visitor
We will cover each and every pattern one by one.
We will try to understand fundamentals about each pattern and then make a code walkthrough.
Hope you enjoyed reading this article. Hope to see some good comments.