What Are Design Patterns?

Get an introduction to what design patterns are and what you’re about to learn in this course.


Design patterns are something that we’ll need to get familiar with as programmers who work with object-oriented languages. This is primarily because they represent well-defined solutions to common software development problems. So, instead of thinking through all the details of our solution, we can simply check if any of the existing design patterns can be used. We won’t have to reinvent the wheel.

As software developers, we would be familiar with reusable software components, such as methods, functions, public classes, libraries, etc. Well, we can think of design patterns as reusable solutions to common software problems. If we’re familiar with which design patterns can solve a specific type of problem, we’ll no longer have to come up with a bespoke solution, which can take us a significant amount of time to design and implement. All we have to do is just pick the most suitable design pattern and apply it in a specific way to solve this specific problem. The solution is already there. The time taken to implement it won’t be much greater than the time it takes us to type the code.

Let’s go through a quick overview of what they are:

What are design patterns?

Design patterns are prescribed ways of implementing solutions to common problems. While every specific implementation of them is bespoke and only relevant to a specific codebase, they still determine how our code should be structured. A design pattern tells us how different object types in our code should interact with one another. Specific objects have specific roles, which are prescribed by a specific design pattern. However, a specific implementation of those objects would still be relevant only to a specific problem.

We can compare the concept of design patterns with Agile principles. For example, if we follow Scrum, we’d go through all of the relevant ceremonies (daily standups, sprint reviews, etc.). We’d have specific roles (Scrum master, product owner, and Scrum team members). We’d work in sprints of a specific length. However, the problems that we’d be solving during our sprints would be very specific to our organization. The actual implementation of the Scrum methodology would be bespoke.

Note: Design patterns have been used in object-oriented programming for some time. In 1994, they were officially classified and described in a book called Design Patterns: Elements of Reusable Object-Oriented Software, which was written by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, who are collectively known as The Gang of Four.

So, each design pattern prescribes how the objects in our code should be structured and how they should behave. For solutions where multiple objects are involved, it prescribes the role of each object.

Some design patterns don’t even involve multiple objects with different roles. Singleton and Prototype patterns, for example, prescribe how to apply internal logic to an object and what public members this object should have for other objects to access.

So, why should we use design patterns? Why not just provide a bespoke solution to every problem we face? Well, there are some good reasons why design patterns are better. The reasons why we would want to learn them go beyond the fact that design patterns merely provide a better solution.

Why would we want to learn design patterns?

Design patterns make us more effective at solving problems. When we’ve used them for a while, we’d intuitively know where to apply them. So, we wouldn’t have to spend much time thinking of a solution. We’ll be able to apply one right away.

Not only will we be able to solve the problem quicker, but our code will be cleaner. It’ll be more readable, easier to test, and easier to maintain.

However, the benefits of knowing design patterns go beyond them being good solutions to common problems. Many reputable organizations ask questions about them during job interviews. The major IT giants almost certainly do. So, not knowing design patterns might prevent us from getting a job in the company of our dreams.

The main problem with design patterns is that they’re not necessarily easy to learn. Let’s examine why that is.