Skip to main content

Introduction to Design Patterns

In software engineering, a Design Pattern is a general, reusable solution to a commonly occurring problem within a given context.

Design patterns are not finished code that can be translated directly into source code; rather, they are templates or blueprints for how to solve a problem that can be used in many different situations.


The Gang of Four (GoF)

The concept of Design Patterns in software engineering was popularized in 1994 by the book "Design Patterns: Elements of Reusable Object-Oriented Software".

The four authors of this book (Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides) are famously referred to in the industry as the Gang of Four (GoF). They cataloged 23 fundamental design patterns that are still widely used today.


The Three Categories

The Gang of Four divided the 23 design patterns into three main categories based on their purpose:

1. Creational Patterns

These patterns provide various object creation mechanisms, which increase flexibility and reuse of existing code. They abstract the instantiation process, making a system independent of how its objects are created, composed, and represented.

  • Examples: Singleton, Factory Method, Builder.

2. Structural Patterns

These patterns explain how to assemble objects and classes into larger, more complex structures while keeping these structures flexible and efficient. They rely heavily on inheritance and interfaces to compose interfaces or define ways to compose objects.

  • Examples: Adapter, Decorator, Facade.

3. Behavioral Patterns

These patterns are concerned with algorithms and the assignment of responsibilities between objects. They not only describe patterns of objects or classes but also the patterns of communication between them.

  • Examples: Observer, Strategy, Command.

[!NOTE] Learning all 23 patterns at once can be overwhelming. In this module, we will focus on the 7 most heavily used and interviewed design patterns in the modern Java ecosystem. Understanding these 7 patterns will give you a massive advantage in system design and architecture!