JavaScript Design Pattern
Before going into details about each design pattern in JavaScript, it would serve as a guideline to first define what a design pattern is. With the help of various resources, I outlined the characteristics and tradeoffs of a design pattern as follows:
✅ A design pattern recognizes patterns in recurring problems in software design.
✅ Each pattern lets us take certain factors into consideration, such as performance, readability, and reusability when we look for a solution to a problem.
✅ Each pattern provides us with tested, proven strategies that are built upon the experiences of developers who came before us.
✅ Each pattern provides us with a good habit to develop, thanks to which we don't have to analyze problems and discuss every possible strategy, and their tradeoffs every time we face recurring problems. Design pattern saves time and energy from the repetitive, mundane problem.
✅ Eventually it helps focus on more unique and interesting problems.
✅ Each pattern provides us with a common vocabulary to describe problems. Using such vocabulary, we can communicate and find solutions much more effectively than by describing the problem at the code level.
✅ Categorization and size of a pattern vary. Some patterns might actually be an overlap or a collection of multiple patterns, while some are a part of bigger patterns and cover smaller problems like variable naming.
✅ A design pattern is not a particular implementation but a general idea of problem-solving. It makes a pattern more flexible and leaves room for developers to adapt patterns to their own situations and improve them for more optimal use.
✅ Some programming languages embrace well-known design patterns into their standard features. While the design pattern itself is language-independent, understanding the design pattern can help a deeper understanding of the language.
Taking this checklist as a guide rope, we will go on to cover some of the well-established design patterns in JavaScript and see what they can offer and what circumstances they suit the best.
Creational Pattern
Singleton Pattern
Factory Pattern
Prototype Pattern
Structural Pattern
Behavioral Pattern
Observer Pattern
State Pattern
Compound Pattern
Module Pattern
References
Implementation Patterns, Beck, Kent. Addison Wesley, 2008. pp. 5-8
Learning JavaScript Design Patterns, Osmani, Addy. O'Reilly
코어 자바스크립트(Core JavaScript), 재남, 정. 위키북스, 2019. pp. 156-174