Book Review: Design Patterns in Ruby

DesignPatternsInRubyI recently finished reading Design Patterns in Ruby by Russ Olsen. I picked this up as I wanted to learn more about the Ruby language, but in a context with which I’m already familiar.

Design Patterns in Ruby shows how you can leverage Ruby to implement the classic Gang of Four design patterns. As someone who is already familiar with how to implement most of these in C#, it was interesting to see how you can use the unique features of the Ruby language to achieve the same result with much less code.

The book is presented in a good quality hardcover and begins by explaining the purpose of design patterns and then provides a short introduction to the Ruby language.

After this, the book introduces several design patterns in turn, often building on the knowledge learned from implementing the previous one. Olsen first explains the pattern, what it could be used for and then provides a ‘classic’ implementation of the pattern. After explaining how the implementation works, it is then refactored (often in several stages) to make better use of Ruby language features, significantly shortening the amount of code in the process.

I thought this approach worked very well – it clearly introduces the pattern and helps the reader understand how to implement it before diving in to the Ruby magic.

The patterns covered by the book are:

  • Template Method
  • Strategy
  • Observer
  • Composite
  • Iterator
  • Command
  • Adapter
  • Proxy
  • Decorator
  • Singleton
  • Factory
  • Builder
  • Interpreter

After this, the book focuses on some ruby-specific patterns such as building DSLs as well as how to use meta-programming to customise objects.

Overall, I very much enjoyed the book. I thought it was written very clearly and the approach that Olsen takes to explain each pattern both concisely explains the purpose of the pattern as well as introducing the reader to Ruby language features. As a C# developer with little Ruby experience, I found the examples easy to follow and learned a lot in the process.

It also acts as a great reference on the GoF patterns, meaning that it has a high re-readability in the future.

Written on December 15, 2010