Posts about Design Patterns
In a previous blog post I created some helper classes and methods to make test code more reusable. One of those classes had a constructor with 3 parameters, but the number of its parameters could easily grow to 10 or more as the test scenarios became more complex and configurable. The builder design pattern is very applicable in such cases, especially if parameters are optional and don't always need to be set.
Immutable objects can't change after they've been created. Because of this, all data needed for their initialization must be passed into them through the constructor. This can result in constructors with (too) many parameters. With the builder design pattern, this can be avoided.
As one could expect based on the title of the book, all of the code samples are written in TypeScript. However, the concepts presented are more generally applicable and not language specific. I would recommend the book to any developer who can fluently read JavaScript/TypeScript (or any other C-based language).
A while ago I've already written a blogpost on how to inject a different Angular service implementation based on a runtime value. With that approach, the selected service was initialized at startup and remained the same for the entire application lifetime. In response to that blogpost, I received a question how one could switch between the implementations while the application is running. This blogpost is my detailed answer to that question.
This book is a recommended reading not only for JavaScript developers, but also for others who want to refresh or expand their knowledge of design patterns. Learning some JavaScript in the process is just an additional benefit.