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