Design Patterns in Ruby: Introduction

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: ,


About Stefano

Stefano Mancini is a co-founder of DevInterface.

After graduating in Computer Science, he first specialized in Java/J2EE development by participating in several international projects in the pharmaceutical and banking ambits.

Enthusiast of agile development, like SCRUM for project management and eXtreme Programming for code writing, he then moved to dynamic languages like Ruby and Python.

About DevInterface

We are an information and communication technology agency. Our mission is to provide web application development, design services and communication strategies. We specialize in building web applications with modern and efficient frameworks.

Related Post

7 Responses to “Design Patterns in Ruby: Introduction”

  1. [...] 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 [...]

  2. [...] posts from this serie: Design Patterns in Ruby: IntroductionShare/Bookmark About stefanoIndependent Information Technology and Services Professional Tagged [...]

  3. Tad Thorley says:

    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?

  4. Stefano says:

    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.

  5. Stephen Touset says:

    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

  6. [...] posts from this series: Design Patterns in Ruby: Introduction Design Patterns in Ruby: Abstract FactoryShare/Bookmark About stefanoIndependent Information [...]

Leave a Reply

Insert code beetween <code lang="ruby"> and </code>

Copyright 2012 DevInterface s.n.c.

DevInterface Blog is proudly powered by WordPress