Summary

In this chapter, we learned how some of the traditional GoF design patterns can be applied to JavaScript and, in particular, to the Node.js philosophy. Some of them were transformed, some were simplified, others renamed or adapted as part of their assimilation by the language, the platform, and the community. We emphasized how simple patterns such as factory can greatly improve the flexibility of our code and how with Proxy, Decorator, and Adapter we can manipulate, extend, and adapt the interface of existing objects. Strategy, State, and Template, instead, have shown us how to split a bigger algorithm into its static and variable parts, allowing us to improve the code reuse and extensibility of our components. By learning the Middleware pattern, we are now able to process our data using a simple, extensible, and elegant paradigm. Finally, the Command pattern provided us with a simple abstraction to make any operation more flexible and powerful.

Apart from observing the JavaScript reincarnation of these widely accepted design patterns, we also discovered some new design patterns born and raised specifically in the JavaScript community, such as the Revealing constructor and the Composable factory function patterns. These patterns help to deal with specific aspects of the JavaScript language such as asynchronicity and prototype-based programming.

Finally, we acquired more evidence of how JavaScript is about getting things done and building software by composing different reusable objects or functions instead of extending many little classes or interfaces. Also, for developers coming from other object-oriented languages, it might have looked weird to see how different some design patterns become when implemented in JavaScript; some might feel lost knowing that there might not be only one, but rather many different ways of implementing a design pattern.

JavaScript is a pragmatic language, we said; it allows us to get things done quickly, however, without any kind of structure or guidelines, we are asking for trouble. That's where this book and, in particular, this chapter comes in useful. It tries to teach the right balance between creativity and rigor. It shows not only that there are patterns that can be reused to improve our code, but also that their implementation is not the most important detail; it can vary a lot, or even overlap with other patterns. What really matters is the blueprint, the guidelines, and the idea at the base of the pattern. This is the real reusable piece of information that we can exploit to design better Node.js applications in a fun way.

In the next chapter, we will analyze some more design patterns by focusing on one of the most opinionated aspects of programming: how to organize and connect modules together.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.130.199