Hi Friends,
This
article is related to the Design Patterns in C#. Here I will explain about what is
Design pattern, Why we need Design patterns, Where we can use the design
Patterns, what are the various Classifications of Design Patterns according to
GoF(Gang Of Four) Organization, What are the situation where the Design
Patterns can be useful and finally do we really need to Design Patterns for our
application and then the explanation of each design pattern with examples.
So first
let’s talk about ‘What is the Design
Pattern?’:
Design
Pattern is the way to solve the recurring problems which occur during the
designing of the software applications.
Q. Why we need design patterns?
A. Design patterns are needed to make
the solution more decouples i.e. components should not be dependent to each
other. This will make the solution more maintainable as well as scalable in the
future prospect. In the future, if
the application needs some additional component’s to be added; it will need few
changes rather than changing in the whole application. So to do this, our
solution should be more decoupled. Hence the Design pattern is the way to make
the application more decoupled.
Q. Where we can use Design Patterns:
A. Design patterns are used in the
solutions, where there is the need to scale the application in the future and
to make the application more maintainable. If there is no scope of maintenance
and scalability in the solution, Design Pattern is not the preferred way to
implement as it will slow down the performance of the overall application.
Q. Classifications of Design
Patterns according to GoF:
A. According to the GoF (Gang of Four)
company, the design patterns can be classified in to 3 groups:
1. Creational
Design Patterns
2. Structural
Design Patterns
3. Behavioral
Design Patterns
Creational Design Patterns: When the design pattern is used in
the creating of the new object, creational design patterns are used. There are
few design patterns which comes under this category-
· Factory & Abstract Factory Design Pattern
· Builder Pattern
· Singleton Pattern
· Prototype Pattern
· Lazy Initialization Pattern
· Builder Pattern
· Singleton Pattern
· Prototype Pattern
· Lazy Initialization Pattern
Structural Design Patterns: When the design pattern is applied
in the structure of the object, structural design patterns are used. There are
few design patterns which comes under this category-
·
Facade Pattern
· Adapter Pattern
· Adapter Pattern
·
Bridge Pattern
·
Composite Pattern
·
Decorator Pattern
·
Flyweight Pattern
· Proxy Pattern
Behavioral Design Patterns: When the design pattern is applied
in the behavior of the object, behavioral design patterns are used. There are
few design patterns which comes under this category-
·
Strategy Pattern
·
Observer Pattern or Publish-Subscribe Pattern
·
Chain of Responsibility Pattern
·
Command Pattern
·
Interpreter Pattern
·
Iterator Pattern
·
Mediator Pattern
·
Memento Pattern
·
State Pattern
·
Template Pattern
Q. Situations where the Design
patterns are useful:
A. When the application is large and scalable
as well as it needs modifications in the coming future, Design Pattern is the
best way to implement to make the solution more de-coupled so that individual
components of the application should not be dependent to each other and the
modification in one component should not affect the others.
Q. Do we really need to Design Patterns?
A. It’s always a good practice to use
the Design patterns while developing the applications. Design Patterns will be
more useful when the project scope could be increasing in future. But it is
not mandatory to use design pattern when the scope of the project is limited
and in the future the project will not be scalable.
Q. Explain about the Creational Design Patterns? Why they called as Creational Design Patterns?
A.
Q. Explain about the Structural Design Patterns? Why they called as Structural Design Patterns?
A.
Q. Explain about the Behavioral Design Patterns? Why they called as Behavioral Design Patterns?
A.