Design Patterns in Ruby
By Anup Biswal
Agenda
● Goal of the talk
● Design Patterns WHAT, WHY
● Dynamic nature of Ruby
● Various patterns with examples and use
cases
WHAT
General reusable solution to a commonly
occurring problem
WHY
mcioffeae ?????
Ruby is dynamic
What do you mean?
Quiz
Some of the patterns we always use?
HOW
● Creational
● Structural
● Behavioural
Creational
● Builder
● Factory
● Singleton
Builder
The purpose of the Builder Pattern is to create an abstract blueprint describing
the steps of creating an object, and then allow many different implementations
to actually carry out that process as long as they provide the necessary steps
Factory
The Factory Method Pattern is used for putting a layer of abstraction on top of
object creation so that directly working with its constructor is no longer
necessary. This process can lead to more expressive ways of building new
objects, and can also allow for the creation of new objects without explicitly
referencing their class.
Singleton
The Singleton pattern is used in situations where a single instance of a class is
all you need. Singleton objects are meant provide an effective way of organizing
global state and behavior, such as configuration data, logging support, or other
similar needs
Structural
● Adapter
● Decorator
● Proxy
Decorator
While there is a more clear distinction between a Decorator and a Proxy in
static languages, in Ruby the two concepts almost merge, except that a
Decorator is used almost exclusively for the purpose of adding / extending
behavior of a target object, and a Proxy is a more general concept
Adapter
An Adapter is used when you want to provide a unified interface to a number of
different objects that implement similar functionality
Proxy
A Proxy is any object that acts as a drop-in replacement object that does a bit of
work and then delegates to some other underlying object
Behavioural
● Command
● Strategy
● Observer
Command
The command pattern is a behavior design pattern used to store the
information necessary to call methods at a future time.
Strategy
The basic idea is to delegate tasks to encapsulated algorithms which are
interchangable at runtime.
Observer
The observer pattern is for event driven programming.
An object, called the subject, maintains a list of its dependents, called
observers, and notifies them automatically of any state changes, usually by
calling one of their methods.

Design Patterns in Ruby

  • 1.
    Design Patterns inRuby By Anup Biswal
  • 2.
    Agenda ● Goal ofthe talk ● Design Patterns WHAT, WHY ● Dynamic nature of Ruby ● Various patterns with examples and use cases
  • 3.
    WHAT General reusable solutionto a commonly occurring problem
  • 4.
  • 5.
  • 6.
    Quiz Some of thepatterns we always use?
  • 7.
  • 8.
  • 9.
    Builder The purpose ofthe Builder Pattern is to create an abstract blueprint describing the steps of creating an object, and then allow many different implementations to actually carry out that process as long as they provide the necessary steps
  • 10.
    Factory The Factory MethodPattern is used for putting a layer of abstraction on top of object creation so that directly working with its constructor is no longer necessary. This process can lead to more expressive ways of building new objects, and can also allow for the creation of new objects without explicitly referencing their class.
  • 11.
    Singleton The Singleton patternis used in situations where a single instance of a class is all you need. Singleton objects are meant provide an effective way of organizing global state and behavior, such as configuration data, logging support, or other similar needs
  • 12.
  • 13.
    Decorator While there isa more clear distinction between a Decorator and a Proxy in static languages, in Ruby the two concepts almost merge, except that a Decorator is used almost exclusively for the purpose of adding / extending behavior of a target object, and a Proxy is a more general concept
  • 14.
    Adapter An Adapter isused when you want to provide a unified interface to a number of different objects that implement similar functionality
  • 15.
    Proxy A Proxy isany object that acts as a drop-in replacement object that does a bit of work and then delegates to some other underlying object
  • 16.
  • 17.
    Command The command patternis a behavior design pattern used to store the information necessary to call methods at a future time.
  • 18.
    Strategy The basic ideais to delegate tasks to encapsulated algorithms which are interchangable at runtime.
  • 19.
    Observer The observer patternis for event driven programming. An object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.