Blog

Design Patterns

published 2021-08-07

Introduction

Writing software is a creative process. In a more literal sense you actively create code, and more figuratively, a big part of writing code is solving problems. As with every other creative process, everyone (even when tasked with a similar task) will probably come up with a fairly unique solution.

Writing software is also an exercise in planning and organization. Good code is readable, easy to follow, and doesn't take too long to acclimatize to. As a result of this, it has become good practice to have code that does similar things structured similarly, solve similar problems similarly, etc. This makes it so your code is predicable and easy to follow; in other words it meets all the aforementioned requirements of "good code."

What Are Design Patterns?

This process of making similar pieces of functionality similar in code can be seen as patterns. If you have a problem that is similar to another one, then a similarly-shaped solution makes your code easier to follow.

A Design Pattern is a predefined solution to a common problem. There are many industry-standard ones out there (which you can find in the links at the bottom), but they can also exist at a team or even a personal level.

Why Use Them

Certain problems (e.g. object creation) come up in lots of places, be it in web development or system-level scripts. Different members of software-development teams also often encounter similar problems. This is where design patterns come in. Rather than every person who encounters a problem coming up with their own solution, design patterns make it so that every similar problem is addressed similarly.

This means that entire codebases, whether written by one person or a whole company, are more uniform. While this might seem like it stifles creativity in the code-writing process (and perhaps to some extent it does), it makes code easier to build upon, easier to understand, and easier to reuse in the future. In other words, it is just prudent.

Some Places To Learn More About Design Patterns

Learning JavaScript Design Patterns by Addy Osmani

Design Patterns by the Gang of Four