Tuesday, July 31, 2012

Design patterns in Ruby


http://rubylearning.com/blog/2010/11/02/how-does-one-use-design-patterns-in-ruby/ :


I believe that the essence of design patterns is to make a system resilient to changes in requirements which in itself could be attributed with the parameters associated with the problem definition. The above article helped me with a lucid set of ruby examples demonstrating following patterns:
(The comments are for my personal notes. Plz ignore them)
1. Inheritance  : Car < Vehicle
2. Composition over inheritance : Car<Vehicle, Car->Engine
3. Delegation ; Car<Vehicle, Car->Engine
4. Template Method pattern : HTMLReport<Report, TextReport<Report
5. Singleton pattern : require 'singleton', attr_accessor :data
6. Adapter pattern : Renderer, TextObject, DifferentTextObject, TextObjectAdapter, class << diff_text_obj

Thanks and Regards,
Tapomay




No comments:

Post a Comment