People have been writing code in object-oriented languages for a long time and, as you might guess, have figured out common ways to solve common problems. These are called design patterns and there are quite a few of them.
In 1994 a group of programmers got together and started discussing various patterns they had discovered in the code they were writing. In the same way that the Romans created the arch and Brunelleschi created a massive dome – the Gang of Four (as they became known) gave object-oriented programmers a set of blue prints from which to construct their code. The Gang of Four are:
- Erich Gamma
- Richard Helm
- Ralph Johnson
- John Vlissedes
Let's have a look at the most common design patterns that I've used and had to know about during my career. I'll be using ES6 here because … well why not? Also, these patterns apply primarily to object-oriented programming (OOP) and are easily adaptable to JavaScrpt.
Creational Patterns
When working with an OO language you need to create objects. It's a simple operation, but sometimes having some rules in place will help create the correct object, with the proper state and context.
The Code
You can find the code for each of the demos up on GitHub.