Design Patterns in Ruby

Design Patterns in Ruby

I gave talk on Design Patterns in Ruby at 'Pune Ruby Users Group' meeting on 6th July, 2013. Here are the code snippets https://gist.github.com/anildigital/5939892

anildigital

July 06, 2013

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

20 slides
  1. What are Design Patterns? Design Patterns are nothing but decent

    pre-loaded solutions to common problems Sunday, 7 July 13
  2. What are Design Patterns? They are worth knowing because they

    are solutions to common problems Sunday, 7 July 13
  3. Are ‘Design Patterns’ restricted to certain programming languages? NO! They

    are programming language independent. They can be implemented in any programming language Most OOP-specific design patterns may be irrelevant to functional languages Sunday, 7 July 13
  4. Design Patterns book by Gang of Four It made Design

    Patterns popular Sunday, 7 July 13
  5. Design Patterns categories Creational patterns (Singleton, Builder etc) Structural patterns

    (Adapter, Composite, Proxy etc) Behavioral patterns (Command, Strategy, Observer etc) Architectural patterns (MVC - Model View Controller etc) Concurrency patterns (Reactor, Thread pool etc) Sunday, 7 July 13
  6. Design Patterns we will see are Template Method Strategy Proxy

    Composite Adapter Decorator Sunday, 7 July 13
  7. Template Method Document def render render_title(@title) render_footer(@author) ... end HTML

    Document Text Document def render_title(t) end def render_author(a) end def render_title(t) end def render_author(a) end Template Method Sunday, 7 July 13
  8. Strategy Document def initialize(renderer) @renderer = renderer end def render

    @renderer.render(self) end HTMLRenderer TextRenderer def render(doc) puts doc.title puts “By #{doc.author}” end def render(doc) ... end Sunday, 7 July 13
  9. Proxy Document def render(doc) puts doc.title puts “By #{doc.author}” end

    ProxyDoc def render if allowed? @doc.render end end client Sunday, 7 July 13
  10. Composite Document def render end Composite def render @subdocs.each do

    |s| s.render end end client Document def render end Document def render end Sunday, 7 July 13
  11. Decorator Document def render end Decorator def to_japanese translate(@doc.paragraphs) end

    def render @doc.render + “do awesome” end client Sunday, 7 July 13

More Decks by anildigital

Other Decks in Programming