Design Patterns in Ruby: Introduction
11:30 AMDevelopment, General, Metodologies, RubyStefano
Hello everyone.
With this post I would like to start a serie of articles concerning the description of the most common design patterns and how these can be applied with the Ruby language.
In the world of software engineering you don’t need to reinvent the wheel to face daily problems: these problems are often very common and in most cases they require a similar resolution.
Christopher Alexander says that “each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such way that you can use this solution a million times over, without ever doing it the same way twice“.
In 1995, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, starting from the work of Christopher Alexander and Kent Beck, have published “Design Patterns: Elements of Reusable Object-Oriented Software.” With this book, the four authors (from then knowned as GoF, Gang of Four) have proposed solutions to the 23 most common and recurring problems in software engineering.
The GoF have analyzed and divided the 23 patterns into 3 categories:
Creational patterns
- Abstract Factory
- Builder
- Factory Method
- Prototype
- Singleton
Structural patterns
- Adapter
- Bridge
- Composite
- Decorator
- Facade
- Flyweight
- Proxy
Behavioral patterns
- Chain
- Command
- Interpreter
- Iterator
- Mediator
- Memento
- Observer
- State
- Strategy
- Template
- Visitor
We will see during this series all the most common patterns: we’ll analyze the problem and define a solution if possible using the potential provided by the Ruby language.
All showed code will be freely accessible in an out repository on GitHub at this address: design_patterns_in_ruby.
Tags: design patterns, ruby

















[...] ORIGINAL POST [...]
[...] This post was mentioned on Twitter by Ruby Reflector, Dev Interface. Dev Interface said: "Design Patterns in Ruby: Introduction Design Patterns in Ruby: Introduzione" – http://bit.ly/9AxnMj [...]
[...] posts from this serie: Design Patterns in Ruby: IntroductionShare/Bookmark About stefanoIndependent Information Technology and Services Professional Tagged [...]
Are you familiar with this book: http://www.amazon.com/Design-Patterns-Ruby-Russ-Olsen/dp/0321490452
It’s essentially the same thing as you’re about to answer in your blog. I’m curious to see if you agree or disagree with Russ Olsen. Also, do you think all of those patterns are applicable to Ruby?
Hello Tad, thanks for your comment.
Yes, I read the book some time ago and I really appreciated.
I was born as a Java developer and I’m still working also in Java.
To this regard, I liked how Russ has shown how to implement these patterns in Ruby.
In particular, the first examples of each chapter has shown an implementation close to the original proposal by the GoF.
In the following examples he then showed how to move from a “Java like implementation” to one more Ruby oriented.
Take for example my next post regarding the Abstract Factory (http://blog.devinterface.com/2010/06/design-patterns-in-ruby-abstract-factory).
If you read the comments, many have pointed out that this pattern is useless in Ruby.
They are right and actually my post is missing a final example that highlights this fact.
I hope to have the time this evening to update the post.
Quite frankly, a huge number of these design patterns are completely irrelevant in a dynamically-typed language with closures like Ruby. http://blog.plover.com/prog/design-patterns.html
[...] posts from this series: Design Patterns in Ruby: Introduction Design Patterns in Ruby: Abstract FactoryShare/Bookmark About stefanoIndependent Information [...]