Design Patterns provide solutions to the commonly occurring problems
in software design. The design patterns were first introduced by GoF(Gang of Four)
where they described the common patterns as problems which occur over and over again and solutions to those problems.
Design patterns have four essential elements:
The pattern name
is a handle we can use to describe a design problem, its solutions, and consequences in a word or two.The problem
describes when to apply the pattern.The solution
describes the elements that make up the design, their relationships, responsibilities, and collaborations.The consequences
are the results and trade-offs of applying the pattern.Advantages of design patterns:
Design patterns can be classified into three categories:
Creational Pattern
- They are concerned with how the object can be created and they isolate the details of object creation.
Structural Pattern
- They design the structure of classes and objects so that they can compose to achieve larger results.
Behavioral Pattern
- They are concerned with interaction among objects and responsibility of objects.
Singleton Pattern:
It is a type of creational pattern
which provides a mechanism to have only one and one object of a given type and provides a global point of access.