Useful design patterns and a refresher exercise.
UPDATING DAILY UNTIL CONCLUSION! ✍️ 👷🏻♂️ 👨🏻💻
We write code to solve problems. These problems usually have many similarities, and, when trying to solve them, we notice several common patterns. This is where design patterns come in.
A design pattern is a term used in software engineering for a general, reusable solution to a commonly occurring problem in software design.
The underlying concept of design patterns has been around in the software engineering industry since the very beginning, but they weren’t really so formalised. Design Patterns: Elements Of Reusable Object-Oriented Software written by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides — the famous Gang of Four (GoF)—was instrumental in pushing the formalised concept of design patterns in software engineering. Now, design patterns are an essential part of software development and have been so for a long time.
There were 23 design patterns introduced in the original book.
Design patterns are beneficial for various reasons. They are proven solutions that industry veterans have tried and tested. They are solid approaches that solve issues in a widely accepted way and reflect the experience and insights of the industry-leading developers that helped define them. Patterns also make your code more reusable and readable while speeding up the development process vastly. Design patterns are by no means finished solutions. They only provide us with approaches or schemes to solve a problem.
Here we'll have design patterns from an object-oriented point of view and in the context of their usability in modern JavaScript. That is why many classic patterns from GoF may be omitted, and some modern patterns from sources like Addy Osmani’s Learn JavaScript Design Patterns will be included. The examples are kept simple for easier understanding and are hence not the most optimised implementation of their respective design patterns.
Design patterns are usually categorized into three major groups.
As the name suggests, these patterns are for handling object creational mechanisms. A creational design pattern basically solves a problem by controlling the creation process of an object. We will discuss the following patterns in detail: Constructor Pattern, Factory Pattern, Prototype Pattern, and Singleton Pattern.
These patterns are concerned with class and object composition. They help structure or restructure one or more parts without affecting the entire system. In other words, they help obtain new functionalities without tampering with the existing ones. We will discuss the following patterns in detail: Adapter Pattern, Composite Pattern, Decorator Pattern, Façade Pattern, Flyweight Pattern, and Proxy Pattern.
These patterns are concerned with improving communication between dissimilar objects. We will discuss the following patterns in detail: Chain of Responsibility Pattern, Command Pattern, Iterator Pattern, Mediator Pattern, Observer Pattern, State Pattern, Strategy Pattern, and Template Pattern.
Main source: JavaScript Design Patterns. The ultimate guide to the most useful design patterns