No history yet

Introduction to Design Patterns

What Are Design Patterns?

When building a house, you don't reinvent the concept of a door or a window. You use established solutions that have been refined over centuries. Software development is similar. Developers often face the same kinds of problems again and again, and over time, they've found elegant, efficient ways to solve them.

These proven solutions are called design patterns. They aren't finished code you can copy and paste. Instead, they are more like blueprints or templates. They describe a common problem and outline a way to solve it that is flexible, reusable, and easy to maintain.

Design patterns are proven solutions to common problems in software design.

A key benefit of using design patterns is communication. When a developer says they're using a "Singleton" pattern, other developers on the team immediately understand the structure and intent of the code without needing a lengthy explanation. It creates a shared vocabulary that makes collaboration much smoother.

A Brief History

The idea of patterns didn't actually start with software. It was first popularised by an architect named Christopher Alexander in the 1970s. He wrote about common problems in designing buildings and towns, and documented standard solutions for them.

In 1994, this concept was formally brought into the software world with the book Design Patterns: Elements of Reusable Object-Oriented Software. The authors, Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, became famously known as the "Gang of Four," or GoF.

Their book catalogued 23 classic design patterns, which are still widely used and form the foundation of many modern software applications.

The Three Main Types

The Gang of Four organised their 23 patterns into three main categories based on their purpose. Understanding these categories helps you know when and where to look for a solution.

1. Creational Patterns These patterns deal with object creation mechanisms. They try to create objects in a manner suitable to the situation. Instead of creating objects directly using the new operator, these patterns give you more flexibility in deciding which objects need to be created for a given use case.

2. Structural Patterns These patterns are about organising different classes and objects to form larger structures and provide new functionality. They focus on how objects are composed to build relationships between them.

3. Behavioral Patterns These patterns focus on how objects communicate with each other. They identify common communication patterns between objects and realise these patterns. By doing so, they increase flexibility in carrying out this communication.

Think of it this way: creational patterns are like the factory that makes the bricks, structural patterns are like the blueprint for the house, and behavioral patterns are like the rules for how people move around inside it.

We will explore specific patterns from each of these categories in the articles to come.

Quiz Questions 1/5

What is the best description of a software design pattern?

Quiz Questions 2/5

The idea of patterns was first popularised in a field outside of software development. Which field was it?