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:

  1. The pattern name is a handle we can use to describe a design problem, its solutions, and consequences in a word or two.
  2. The problem describes when to apply the pattern.
  3. The solution describes the elements that make up the design, their relationships, responsibilities, and collaborations.
  4. The consequences are the results and trade-offs of applying the pattern.

Advantages of design patterns:

  1. They are reusable across multiple projects.
  2. The architectural level of problems can be solved
  3. They are time-tested and well-proven, which is the experience of developers and architects
  4. They have reliability and dependence

Design patterns can be classified into three categories:

  1. Creational Pattern
  2. Structural Pattern
  3. Behavioral Pattern

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.