Design Patterns in Ruby


Published on

Although most of the design patterns are generic, this upload is mainly for folks who have some experience of Ruby and preferably Rails.The main focus is to make folks AWARE of various desing patterns that exists. Most of the patterns are taken from Gof Design Patterns.

Published in: Software, Technology, Education
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Design Patterns in Ruby

  1. 1. Design Patterns in Ruby By Anup Biswal
  2. 2. Agenda ● Goal of the talk ● Design Patterns WHAT, WHY ● Dynamic nature of Ruby ● Various patterns with examples and use cases
  3. 3. WHAT General reusable solution to a commonly occurring problem
  4. 4. WHY mcioffeae ?????
  5. 5. Ruby is dynamic What do you mean?
  6. 6. Quiz Some of the patterns we always use?
  7. 7. HOW ● Creational ● Structural ● Behavioural
  8. 8. Creational ● Builder ● Factory ● Singleton
  9. 9. 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
  10. 10. 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.
  11. 11. 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
  12. 12. Structural ● Adapter ● Decorator ● Proxy
  13. 13. 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
  14. 14. Adapter An Adapter is used when you want to provide a unified interface to a number of different objects that implement similar functionality
  15. 15. 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
  16. 16. Behavioural ● Command ● Strategy ● Observer
  17. 17. Command The command pattern is a behavior design pattern used to store the information necessary to call methods at a future time.
  18. 18. Strategy The basic idea is to delegate tasks to encapsulated algorithms which are interchangable at runtime.
  19. 19. 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.