
Pro JavaScript Design Patterns
For a while I’ve been meaning to read a book on design patterns, which are ways to design and structure solutions to common problems in order to create efficient and optimal results. I missed a chance to take a course on them back in college when I took Cryptology instead, and have since been meaning to sit down and read up on what’s been developed and what can be useful to me. So it was to my happy surprise when I stumbled across
Pro JavaScript Design Patterns
in the book store a while back.
The book is broken into two parts. The first part explains how object oriented programming concepts work in JavaScript and how to implement the ones that aren’t built into the language, such as interfaces and private members. The second part of the book focuses on a common set of design patterns and how they can be implemented in JavaScript. It covers the following patterns, giving a chapter on each one: Singleton, Factory, Bridge, Composite, Facade, Adapter, Decorator, Flyweight, Proxy, Observer, Command and Chain of Responsibility.
Before I go any further, while I’m going to write a mostly positive review for this book, I should say that I initially tried to read it around 18 months ago, but stopped after I finished the first section. I re-read it from start to finish about 2 months ago. I stopped the first time I tried to read it because the book introduces a lot of ideas and I was a little confused on some of the concepts it touched on. Specifically, I was confused with how constructor functions worked and how a function’s prototype property worked. I got distracted trying to understand this and picked up another book and ended up not coming back to this book (it’s hard for me to get back into a book once I’ve set it down for a while). As for constructor functions and the prototype property, a good explanation of them can be found here.
I had better luck on my second read through and found the second half of the book to be an easy read. Though each chapter focuses on a different design pattern, some of them use patterns introduced in earlier chapters, so it’s actually a good idea to read the chapters in order. Each of these chapters starts by explaining the basic idea behind the pattern and then goes into a couple of real world examples of how the pattern is used. The chapters close by discussing the benefits and drawbacks of the pattern they introduced and some advice is given to help you identify situations where using the pattern would be a good idea.
Overall, I found this be to be extremely interesting. I could possibly have learned about the different design patterns by reading online tutorials, but being able to look at solutions in JavaScript was very helpful. Also, after reading certain chapters, I felt like going back and rewriting some of my old apps (though I’ll contain myself). Knowing about this collection of design patterns is a huge plus for me and for that alone I’m glad I read this book. I wouldn’t recommend this book to someone who doesn’t have a good understanding of prototypal inheritance, but if you feel like you do, this book is worth checking out. If you don’t, I would recommend looking up some design pattern tutorials online and trying to learn about the common patterns, you’ll be glad you did.
On a side note, I was also amazed at how many of these patterns I’d seen before. It certainly gave me a better appreciation for some of the code bases I’ve seen in the past. I also found that I used some of the patterns already unknowingly, but that I didn’t have a name for the technique I was using.
If I could go back in time I would still probably take that Cryptology class, but I would also try and read up on Design Patterns too. If you have a few extra minutes, it’s worth reading up on them.