Design Pattern
Design Pattern:
·
Design Patterns are reusable solutions to the
problems that as a developer we encounter in our day to day programming.
·
Writing the code with design patterns will make
your applications more Reliable, Scalable and Maintainable.
·
Used to solve the problems of object generation
and integration.
History of Design Pattern:
·
Concept came from the book “Elements of
Reusable Object-Oriented Software” by 4 authors known as Gang of four.
·
Book divided into 2 parts
o
First part à
pros & cons of OOPs
o
Second partà
the evolution of 23 classic software design patterns.
Types of Design Pattern:
1.
Creational Design Pattern
ü
Deals with object creation & initialization
ü
Gives the program more flexible in deciding
which object need to be created for a given case
ü
Best suit for a project with a lot of classes
with a lot of objects, then objects are scattered on client code which leads
complicated logic at client code i.e. not centralized code. So this pattern
centralized the object creation logic.
ü
Exp. Factory , Abstract factory.. etc
2.
Structural Design Pattern
ü
Deals with class & object composition
ü
Focused on decoupling interface &
implementation of class & its objects.
ü
change in structure of a class or relationship
between the classes but you don’t want the project to be affected.
ü
e.g. customer and product class and the product
class is used inside the customer class (one to many relationships). Later, the
customer wants to keep away the product class as they want to use the product
and customer class independently. This is structural change and you don’t want
this structural change to affect your project. This is where the Structural
Design Pattern helps us.
ü
Exp: Adaptive, Bridge. etc.
3.
Behavioral Design Pattern
ü
Deals with communication between classes &
objects.
ü
change in behavior of a class and again it
affects other classes of the project.
ü
E.g. Invoice class currently applying taxes as
18%. Later if to add another extra tax. That means changing the behavior of a
class.
ü
Exp: Chain of Responsibility, Command etc.
Comments
Post a Comment