Russ Olsen has been building software for more than twenty-five years. He has led projects through several generations of programming technologies, from FORTRAN to C to C++ to Java, and now Ruby. He has been using and teaching Ruby since 2002. Olsen writes the popular technology blog Technology As If People Mattered (http://www.russolsen.com).
A former colleague of mine used to say that thick books about design patterns were evidence of an inadequate programming language. What he meant was that, since design patterns are the common idioms of code, a good programming language should make them very easy to implement. An ideal language would so thoroughly integrate the patterns that they would almost disappear from sight.
To take an extreme example, in the late 80's I worked on a project that produced object oriented code in C. Yes, C, not C++. We pulled this off by having each "object" (actually a C structure) point off to a table of function pointers. We operated on our "objects" by chasing the pointer to the table and calling functions out of the table, thereby simulating a method call on an object. It was awkward and messy, but it worked. Had we thought of it, we might have called this technique the "object oriented" pattern. Of course with the advent of C++ and then Java, our object oriented pattern disappeared, absorbed so thoroughly into the language that it vanished from sight. Today, we don't usually think of object orientation as a pattern—it is too easy.
But many things are still not easy enough. The justly famous Gang of Four book, (Design Patterns: Elements of Reusable Object-Oriented Software by Gamma, Helm, Johnson, and Vlissides) is required reading for every software engineer today. But actually implementing many of the patterns described in Design Patterns with the languages in widespread use today, Java and C++ and perhaps C#, looks and feels a lot like my 1980s vintage handcrafted object system. Too painful. Too verbose. Too prone to bugs.
The Ruby programming language takes us a step closer to my old friend's ideal, a language that makes implementing patterns easy, so easy that sometimes they fade into the background. Building patterns in Ruby is easier for a number of reasons:
All of this makes code in Ruby compressible: In Ruby, like Java and C++, you can implement very sophisticated ideas, but with Ruby it is possible to hide the details of your implementations much more effectively. As you will see on the pages that follow, many of the design patterns that require many lines of endlessly repeated boiler plate code in traditional static languages require only one or two lines in Ruby. You can make a class into a singleton with a simple include Singleton. You can delegate as easily as you can inherit. Since Ruby enables you to say more interesting things in each line of code, you end up with less code.
This is not just a question of keyboard laziness, it is an application of the DRY (Don't Repeat Yourself) principal. I don't think anyone today would mourn the passing of my old object oriented pattern in C—it worked for me, but it made me work for it, too. In the same way, the traditional implementations of many design patterns work, but they make you work too. Ruby is a real step forward to be able to do that work only once and compress it out of the bulk of our code. In short, Ruby allows us to concentrate on the real problems that we are trying to solve instead of the plumbing. I hope that this book will help you see how.
Simply put, this book is for developers who want to know how to build significant software in Ruby. I assume that you are familiar with object oriented programming, but you don't really need any knowledge of design patterns —you can pick that up as you go through the book.
You also don't need a lot of Ruby knowledge to read this book profitably: you can find a quick introduction to the language in Chapter 2 and I do try to explain any Ruby specific language issues as we go.
This book is divided into three parts. First there are a couple of introductory chapters, starting with the briefest outline of the history and background of the whole Design Patterns movement and ending with a quick tour of the Ruby language, at the "just enough to be dangerous" level.
The second section, which takes up the bulk of these pages, looks at a number of the original Gang of Four patterns from a Ruby point of view. What problem is this pattern trying to solve? What does the traditional implementation of the pattern, the implementation given by the Gang of Four look like in Ruby? Does the traditional implementation make sense in Ruby? Does Ruby provide us with any alternatives that will make solving the problem easier?
The final section of this book looks at a three patterns that have emerged from the Ruby.
I cannot sign my name to a book about design patterns without repeating the mantra that I have been muttering for many years now: design patterns are little spring loaded solutions to common programming problems. Ideally, when the appropriate kind of problem comes along, you should trigger the design pattern and the problem is solved. It is that first part, the bit about waiting for the appropriate problem to come along, that some engineers have trouble with. You cannot say that you are correctly applying a design pattern unless you are confronting the problem that the pattern is supposed to solve.
The reckless use of every design pattern on the menu to solve nonexistent problems has given design patterns a bad name in some circles. I would contend that Ruby makes it easier to write an adapter that uses a factory method to get a proxy to the builder which creates the command which coordinates the operation of adding two plus two. Ruby will make that easier, but even in Ruby it will not make any sense.
Nor can you look at program construction as a simple process of piecing together some existing design patterns in new combinations. Any interesting program is going to have unique sections, bits of code that fit that specific problem perfectly and no other. Design patterns are meant to help you recognize and solve the common problems that arise over and over when you are building software. The advantage of design patterns is that they let you rapidly get past the problems that someone has already solved, so that you can get on to the hard stuff, the code that is unique to your situation. Design patterns are not the universal elixir, the magic potion that will fix all of your design problems. They are simply one technique, albeit a very useful technique, that you can use to build programs.
If you're already a programmer, this book an excellent way to learn Ruby.
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.
The author's style and the book's format make for an easy and informative reading experience.
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... Read morePublished 12 months ago by tomh
As an experienced software developer with very little Ruby experience, I found this book to be a great refresher course on common design patterns as well as a solid introduction to... Read morePublished 14 months ago by Ryan M.
I've only referred to the GoF Pattern book a couple of times in the years when I had something I needed to do and just needed some ideas. Read morePublished on July 17, 2012 by Craig Frooninckx
The content of this book may very well be useful. But opening it in the Kindle reader reveals a huge flaw in the e-book version: the text is largely unformatted. Read morePublished on March 26, 2012 by D. N.
If you already have a good command of Ruby and either know the typical design patterns or are an experienced developer already, then you don't need this book. Read morePublished on November 7, 2011 by David Barri
Coming from another language, I found this book to be a fantastic initiation into Ruby. The quality of the book makes it feel like a more modern and practical version of the... Read morePublished on September 10, 2011 by Joel in Somerville
This is the kind of technical book that comes along maybe once a decade or so: absorbing, informative, and useful to both a novice and expert alike. Read morePublished on October 17, 2010 by S. Hirsch
Russ Olsen delivers an approachable introduction to design patterns using Ruby in a book that is as good for those unfamiliar with design patterns as it is for those unfamiliar... Read morePublished on October 14, 2009 by Z. Adams
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. Read morePublished on April 2, 2009 by Nate Klaiber