0 Shares 1050 Views

Introduction to Design Pattern

Arpatech Oct 25, 2021
introduction-to-design-pattern

Three decades ago, when the software industry was not as big as it is today, software professionals had to use Alexander’s Principles of Urban Design. This task brought about the concept and implementation of design pattern development.

History of Design Pattern

The idea of design pattern was then adopted by four authors: John Vissides, Richard Helm, Erich Gamma, and Ralph Johnson. By using this idea, they published a book called Design Patterns: Elements of Reusable Object-Oriented Software. In this book, the authors applied the design patterns for programming purposes.

The book quickly became the bestseller because it gave 23 amazing solutions to many software designs. It was named “the book by the Gang of Four” or “the GoF book”.

What is Design Pattern?

Design patterns are like a guidebook to all your repetitive and conventional object-oriented problems. They are developed to provide ease to the developers and the general issues that they come across during software development. These reusable solutions have been obtained by regular trial and error by many developers over a period of time.

Design patterns do not recommend the direct implementation of any solution. They are merely an outline or structure that highlights the properties of the solutions that are required and are designed according to the needs of every developer.

With the help of design patterns, software developers get ease in designing new software easily and efficiently. The prerequisite is to understand the software system that a developer is currently working on.

Design patterns present a common language that can be understood by everyone and communicated effectively for a better understanding. When the team of developers gets the idea of every solution, they are able to perform better and exhibit problem-solving skills.

Types of Design Pattern

The GoF design pattern are divided into three categories

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

1.    Creational Design Pattern

The creational design pattern is specified to the class instantiation or the creation of an object. This allows the designers to enhance the flexibility of their method and reuse the code. To get into the depth of this design pattern, it is classified into class-creational patterns and object-creational patterns.

For the use of efficient inheritance in the instantiation, the class-creation pattern is used while with the help of the object-creation pattern, effectual delegation helps the job to get done.

There are three types of Creational Design Pattern

  1. Factory Method Pattern
  2. Builder Pattern
  3. Singleton Pattern

Factory Method Pattern

Factory Method Pattern is the commonly used GoF Creational Design pattern. This is the design that uses the logic of object creation outside the client and then encapsulates it in a class to form a Factory. It gives the interface for object creation in a superclass that changes the object type that has been made.

A Factory Pattern is used when a developer does not want to hand over the control to accessing and implementation of classes to clients. This pattern provides Dependency Inversion.

Builder Pattern

The builder pattern is used when the creation of complex objects is required that can be in any of its components. It lets the developers create complex objects step by step. This pattern enables developers to create various types and representations of objects which is possible when using the same construction code.

The best example of Builder Pattern is the StringBuilder class in Java. StringBuilder makes possible the creation of a String object. String object consists of many strings and its combination with new String object for concatenation.

Singleton Pattern

Singleton is the GoF pattern that is utilized for the creation of one object of a class only. The developer creates the object inside the class and its constructors are declared private to make sure that the instantiation of the class cannot be done from anywhere else.

2.   Structural Design Pattern

A structural design pattern is only concerned with the composition of class and object. By using the concept of inheritance, interfaces are composed that helps define the method for the composition of the object to get new functions.

There are two categories of Structural Design Pattern

Decorator Pattern

It is a structural pattern that allows developers to link new behaviors to object. They place objects inside special object wrappers that have behaviors.

Façade Pattern

Façade pattern gives a simplified interface to any library, complex set of classes, or framework.

3.   Behavioral Pattern

The behavioral design pattern is specified with building and identifying communication between objects. Their focus is algorithms and assigning and creating responsibilities among all objects. Some of the behavioral patterns include Observer, Strategy, Mediator, Iterator, Visitor, Template method, and more.

Behavioral pattern is categorized into three groups such as

Observer Pattern

Observer Pattern helps define the mechanism of subscription and informs objects about events.

Strategy Pattern

Strategy Pattern helps developers to define the algorithm family and place them in different classes and makes objects exchangeable.

Chain of Responsibilities Pattern

Chain of Responsibilities Pattern passes the request with the chain of handlers.

Bottom Line

In the blog, we learned about the design pattern and their types introduced by the Gang of Four. You may use these to strengthen the basics of object-oriented programming and increase your knowledge of the design patterns.

Arpatech
Connect At

Arpatech

Arpatech is a technology hub that’s been operating since 13 years and have provided ingenious business solutions to customers worldwide.
Arpatech
Connect At
CMMI logo