GoF Design Patterns – How to learn them with ease?

The design patterns are the standard, re-usable solution approach for commonly occurring software design problems. Since they are tried and tested solutions based on the design best practices, they provide a safe guide to design our systems the right way.

The Object Oriented Programming is all about creating the objects, building the features and integrating them together to build our solutions.

However, the problem is that we can build and integrate these components in multiple ways. But, if we use this flexibility without a though, we will end up with a chaos. Then, even a simple solution can pose nightmares to build, maintain and enhance.

Fortunately, even if the objects differ, the features change, there are many aspects which keep repeating. For instance, the complexity of the objects, relationship between the objects. Similarly, the compatibility issues during their integration. Also, the way to organize the common and specific features. The design patterns come in handy as they provide tried and tested solutions for such repeating problems.

 

GoF Design Patterns

The famous Gang of Four (GoF) design pattern was published way back in 90’s. It consists of 23 basic patterns, covering the 3 important aspects of our design as mentioned below :

  • Creational Design Patterns – Focuses on the ease of creating the objects.
  • Structural Design Patterns – Guides us on effective ways to integrate the components for the client usage.
  • Behavioral Design Patterns – Focuses on systematically building the features.

The “Gang of Four” refers to the four authors of the book – Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. The name of the book is “Design Patterns : Elements of Reusable Object-Oriented Software”.

Learning them with ease with the Bigger Pictures

The first thing to understand is the significance of the 3 main categories of these patterns.

These categories divides the complexities into 3 key aspects of our design. As a result, we can focus on the creation of objects, development of features and the concerns of integration separately. This greatly simplifies our design compared to when they are mixed up. In other words, it helps us to create flexible, reusable objects and features which are easy to integrate.

Secondly, the patterns in each category divides its problem domain into few complementary concerns.

Even though they address complementary concerns, these patterns often look similar and confusing. Hence, its always important to view these related patterns together in a bigger picture.

Finally, these patterns provide generic approach where we can suitably customize our implementations. Hence, more than the concrete implementations, our focus should be on their use cases and the solution approach. More specifically on when, why and how to use?

In this article, we will look at those bigger pictures that connects these patterns with their use cases. We will look at them in more detail in separate articles.

 

 

Creational Patterns

These patterns hide the complexities of the object creation, so that the clients can create them with ease.

Removing the complexities of the object creation, also help the clients focus more on their usage and simplify building of the features.

For example, a client can use a factory to generalize its business logic. With a simple generalized logic, the client can work on a long list of similar components without depending on any of them.

The diagram below shows the various creational patterns and their usage.

Creational Design Patterns

 

Structural Patterns

Structural Design Patterns guides us on how to structure a re-usable component so that it is easy to integrate, efficient and flexible.

Say, we are building a reusable component. When a client wants to use it, there can be various types of challenges or expectations during their integration. The diagram below summarizes them along with the corresponding GoF structural pattern as its solution.

Behavioral Patterns

 

As shown below, these patterns focus on various ways of adding features ensuring its flexibility and maintainability.

 

Behavioral Design Patterns