Design Patterns in Ruby
N**R
Concise explanation of design patterns, in Ruby.
If you have been programming for any extended period of time, I am sure you have started to see different patterns emerging out of your tasks. You may find you are doing the same thing over and over again, solving problems that you had previously solved in another project. These patterns can vary from smaller chunks of re-usable code, to manage the sending and receiving of email, all the way to watching over a part of your application and triggering notifications to another part of your application. This book, Design Patterns in Ruby takes several of the principles found in the widely known book, Design Patterns by The Gang of Four, and applies them to Ruby. It's a mixture of the theory behind the design patterns, and then hands-on practice applying it to your Ruby applications. While this book is centered around patterns in Ruby, it is not about teaching you Ruby. There is a brief primer in the beginning, but it comes with the understanding that you already know a little bit about the Ruby language. Now it's time to check out some of the patterns presented in this book.WHAT ARE PATTERNS?The book starts off with a chapter devoted to giving background to design patterns and how they can help you build better applications. This chapter isn't a history lesson. The main points of this chapter teach you about awareness. They teach you how to look at your applications, and when and where patterns could best be applied. He gives what he calls Patterns for Patterns while developing:Separate out the things that change from the things that stay the same.Program to an interface, not an implementation.Prefer composition over inheritance.Delegate, delegate, delegate.You ain't gonna need it.These principles provide us the glasses with which to look through as we assess our code. You will want to keep these in the back of your mind as you read through the rest of the book.WHAT IS RUBY?As I stated in the beginning, this book isn't about teaching you Ruby. However, the author does take the second chapter to walk you through the basics. This chapter simply shows you a bit of the syntax, types, and constructs. This intro is very brief, but probably enough to provide a reference throughout the rest of the book if you haven't worked with Ruby before. With this primer into Ruby, the author wraps up the first part of the book and we are now ready to move on to the 14 patterns covered in this book.THE PATTERNSSpotting patterns might not always be easy, even with the guidelines given in the first chapter. One of the strengths of this book is that each chapter poses a different problem and then tackles is using the suggested pattern. This allows you to see it in action, and allows you to get the wheels spinning on how the pattern is used and where else it could be used. After walking through each of the patterns, we are presented with a nice wrap-up of the pattern.This book is not very long in length, so I won't go into great detail with each of the patterns, as they are covered very well in each chapter. You need the context to understand how all of the pieces fit together. So, without providing too much information, here is a list of the patterns covered in the book:Template methodStrategyObserverCompositeIteratorCommandAdapterProxyDecoratorSingletonFactoryAbstract FactoryBuilderInterpreterIf you are like me, then you will have read these chapters and be left with a desire to instantly start researching, practicing, and applying what you have learned. But we aren't done quite yet, there is still one more section to go. We now know what the patterns look like. We have seen the examples done solely in Ruby. Everything makes sense. But can we do more? Now we shift gears to look at patterns found in the Ruby language itself.THE PATTERNS + RUBYThe Ruby language itself has several patterns that make programming Ruby fun and elegant. The last part of this book shows us a few of those patterns, as they can be used extensively while building your application patterns. If you have ever browsed through the Ruby on Rails source code, then you will have seen all of the patterns listed above, as well as the patterns in Ruby. Here are a few of those:Domain-Specific LanguagesMeta-programmingConvention over configurationRuby is such an elegant language to work with, and it is due in many parts to these patterns found within the language. These aren't patterns solely used by Ruby, but the English-like nature of Ruby makes it fun to both read and write with these patterns.PARTING THOUGHTSThis book fits nicely with the Addison Wesley Professional Ruby Series, but doesn't require you to read all other books in the series to fully comprehend. While the progression of this book was done very well, starting you off with a discussion of patterns and Ruby, then diving right into the patterns, I did find myself reading this book several times. I didn't read it several times because I didn't understand it, but simply to read with a new outlook on how and where these patterns could be applied, or are currently applied out in the wild. I find this book not only to be very informative, but also an excellent reference as I look to solve different problems. If you are a programmer, you should definitely read Design Patterns. If you are a Ruby programmer, you should then read Design Patterns in Ruby.
B**I
Engaging and Educational
I am a Java developer whose Ruby experience is limited to firing up the interactive Ruby shell for a Hello World, or reading the first chapters of Programming Ruby before drifting away and vowing to learn Ruby "when I have more time". I work with the author, and purchased this book solely on the strength of his training courses and lectures. Russ Olsen in book-format is just as effective a teacher as he is in person.The book is a hybrid reference/Ruby-introduction book which provides the best of both worlds -- I was able to read it cover-to-cover without losing interest, something I could never quite accomplish with the original GoF Design Patterns text. Each chapter also functions as a modular unit, with concise introductions and conclusions that will be great on a day when I pull it off my shelf for use as a reference book. The Design Patterns provide a nice playpen for the sections on Ruby coding practices and features, and the coding sections give a better context for the Patterns.Each Pattern is discussed in theory and in real-world code, and the author is very clear about the benefits and pitfalls of employing them. In addition, the book provides a solid, likable profile of the Ruby language without the evangelizing common in other books. Code examples are concise and useful, and the writing style is humorously engaging without falling into the trap where engineers-turned-authors suddenly believe they are stand-up comedians and sprinkle every paragraph with a multitude of grating jokes. There were a few mistakes in the text, but all of them were already captured and corrected on the book's web site.In my library of tech books, the best books, the ones I constantly revisit, are not the ones that show me how to do something -- they are the ones that place what I do in a wider context and show me the possibilities of what CAN be done. Although I do not currently use Ruby in my day-to-day work, I can see this book becoming invaluable when that day comes.
T**H
Must read for all serious runt developers
After reading Russ Olsen's Eloquent Ruby years ago, I knew this was a guy who could write. I have recommended that book to numerous people since then, and recently when I was searching for it I found this book. It does not disappoint. If you have read the "gang of four" Design Patterns book you'll recognize most of what Olsen writes about here. But what is amazing and cool is that the book is for rubyists and he demonstrates patterns that are regularly relevant to those of us writing ruby professionally (that includes Rails). And of course there are opportunities to use the beauty of ruby to do in a few lines what I did in many in C++ and Java, so it continues in the vein of instruction I loved so much in Eloquent Ruby. There are even some ruby-specific patterns at the end. I have been writing ruby since 2008 or thereabouts and have written a lot of bad code, and read far more bad code. Read and understand Olsen's books and do the world a favor by seeing ways to follow clean, elegant, simple and regular patterns that make your ruby beautiful.
F**E
Awesome
Best material about design patterns applied to Ruby, great examples and definitely much more light weight than reading the Gang of 4.
A**Z
Bien explicado
El libro está muy completo y cada capítulo tiene ejemplos claros usando Ruby
A**R
Five Stars
Good delivery/ Good read for HDL verification folks too.
J**O
This is a brilliant introduction to patterns regardless of which language you program in!
I've read a few Ruby books and this one has to be my favourite!If you buy any book on patterns, in any language, you will definately be doing yourself a favour and teaching yourself a transferable skill. However, it's more of a "transferable skill" if you are able to:a) understand; andb) rememberthe code in the first place!The consiceness of Ruby and easy-to-read style of the author allow you to do both.Russ doesn't just spoon feed you pattern after pattern. Instead, he presents a series of problems, in which he builds an initial program, and refactors toward the end solution/pattern.What I found especially encouraging along the way is that Russ's ability to point out the use of patterns within the Ruby Language itself and other libraries used. Russ doesn't tell you to boast of his mysteriously aquired knowledge. He admits that his knowledge is the result of rummaging through the source and he encourages/inpires you to do the same.The book covers 14 of the patterns covered by GoF's book however after reading this book you shouldn't have a problem understanding patterns on resources such as Wikipedia or using them to derive a Ruby version if needed.The chapters on DSL's and Metaprogramming are brilliant and will make you really think about what you've learnt in the previous chapters. These chapters alone teach you how to transform Ruby(or <insert meta-programming-langage>) into a powerful tool.You come away from this book a better programmer ready to appreciate and understand libraries like Rails, Docker, Vagrant, Puppet, even JQuery etc down to the file layout. Better still it if you have anything in mind, it puts you in a position to start your own!To get begin your knowledge of patterns with any other book would be your first mistake!
B**.
Sehr gutes Patternbuch und tiefergehender Einblick in Ruby
Nach einer kurzen Einfuehrung der Ruby-Basics geht es direkt los mit den Pattern: Allgemeine Problemstellung des Pattern, erlaeuterung des Loesungsvorschlags der gang-of-four, Umsetzung in Ruby und abschliessend ein Blick ueber den Tellerrand. Gespickt mit passenden Codebeispielen ergibt sich so ein sehr guter Einblick in jedes Pattern und ein ebenso tiefer in die Sprache selber.Eindeutige Empfehlung!!
B**S
デザインパターン初学者以外にもお勧め
パターンとしてはGOFの全てのパターンを網羅しているわけではなく、スタンダードなものにしぼった部分的な解説となっている。加えてRubyの動的言語の特徴に基づいたパターンとして、DSL、メタプログラミングなどの章が追加されている。対象読者として、Rubyでプログラミングをはじめた初学者でこれからデザパタも勉強したい人に最も適していると思う。とは言えJavaなどで既にデザパタを学んでおり、Rubyをそこそこ学んだ人についてもRubyでデザパタを表現する際に、Procやクロージャを使ったりすることで別の表現方法があることを気づかされるという点でメリットは充分ある。私はJavaからRubyに入ったくちで、Javaで既にデザインパターンを学んでいたが、なかなか参考になった。既に邦訳本も出版されていますが、洋書も平易な文章で書かれているので読みやすいです。
Trustpilot
5 days ago
1 day ago