SlideShare a Scribd company logo
1 of 38
Download to read offline
Design Patterns
                                in

                              Ruby

                                     @russolsen   1

Wednesday, July 25, 12
2

Wednesday, July 25, 12
3

Wednesday, July 25, 12
Th ird


                         & Me!
                                  4

Wednesday, July 25, 12
(magma)



                                   edward.og




                                               5
Wednesday, July 25, 12
FORTRAN                   Pascal

                           BASIC
                                      C
                                           C++
                         Python    Java
                               Ruby
                                          Clojure
                                                    6

Wednesday, July 25, 12
Design Patterns:
                          3 Things in 1


                                            7

Wednesday, July 25, 12
Philosophy of

        Good Design
                                         8

Wednesday, July 25, 12
Common Problems

       Common Solutions
                          9

Wednesday, July 25, 12
Some
       Common Solutions

                          10

Wednesday, July 25, 12
More
                           @#$&
                         Documents!
                                      11

Wednesday, July 25, 12
Templates
                             &

                         Strategies

                                      12

Wednesday, July 25, 12
Document
                                      def render
                                       render_title(@title)
                                       render_author(@author)
                                       ...
                                      end




                    PlainDocument                        HtmlDocument
                def render_title(t)                    def render_title(t)
                end                                    end

                def render_author(a)                   def render_author(a)
                end                                    end




                                                                   Template Method   13

Wednesday, July 25, 12
PlainRender
                                         def render(doc)
                                          puts doc.title
                         Document         puts “By #{doc.author}”
                                          ...
                                         end
               def render
                @renderer.render(self)
               end

                                           HtmlRenderer
                                         def render(doc)
                                          ...
                                         end




                                                    Strategy        14

Wednesday, July 25, 12
Separate
                           Out
                         Change
                                    15

Wednesday, July 25, 12
Think Interface
                         NOT
              Implementation
                                   16

Wednesday, July 25, 12
Composition
                            NOT
                         Inheritance
                                       17

Wednesday, July 25, 12
Delegate!

                         18

Wednesday, July 25, 12
Five
                          In
                         Five!
                                 19

Wednesday, July 25, 12
Client




                          “Stand In”             “Real Object”

                     Do something with @real   Do real stuff




                                               Stand In Meta Pattern 20
Wednesday, July 25, 12
What If
                          You
                 Need Control?
                                   21

Wednesday, July 25, 12
Proxy!
                         22

Wednesday, July 25, 12
Client




                          ProxyDoc         Document
                     def render       def render(doc)
                      if allowed?      puts doc.title
                        @doc.render    puts “By #{doc.author}”
                      end              ...
                     end              end




                                             Proxy               23

Wednesday, July 25, 12
What If
                            You
                         Need More?
                                      24

Wednesday, July 25, 12
Decorate!
                         25

Wednesday, July 25, 12
Client




                         Decorator            Document


                def to_japanese
                 translate(@doc.paragraphs)
                end

                def render
                 @doc.render
                end




                                              Decorator   26

Wednesday, July 25, 12
What If
                            You
                         Need Less?
                                      27

Wednesday, July 25, 12
Facade!
                             28

Wednesday, July 25, 12
Client
                                              EnterpriseDoc


                         Facade
                                            10,000 Complex methods
                def render
                 @ent_doc.complex_stuff()
                end




                                                Facade               29

Wednesday, July 25, 12
What If
                         You Need
                    Different?
                                    30

Wednesday, July 25, 12
Adapt!
                                  31

Wednesday, July 25, 12
Client




                           Adapter         Document

                     def print        def render
                      @doc.render      ...
                     end              end




                                            Adapter   32

Wednesday, July 25, 12
What If
                         You Need

                    Little Bits?
                                    33

Wednesday, July 25, 12
Compose!
                         34

Wednesday, July 25, 12
Document
                              Client




                                             Document
                         CompositeDoc
                     def render
                      @subdocs.each do |s|
                        s.render
                      end
                     end                     Document




                                             Composite   35

Wednesday, July 25, 12
Design Patterns are
                          nothing but decent
                         pre-loaded solutions to
                          common problems.



                                                   36

Wednesday, July 25, 12
They are worth your time
                 because of they are
                  solutions, but also
               because they are decent.



                                          37

Wednesday, July 25, 12
russ@russolsen.com
                            @russolsen



                         thinkrelevance.com

                                              38

Wednesday, July 25, 12

More Related Content

Viewers also liked (10)

2016 fundamentos de la práctica docente
2016  fundamentos de la práctica docente2016  fundamentos de la práctica docente
2016 fundamentos de la práctica docente
 
Nicastro y Greco- Resumen: "Entre trayectorias"
Nicastro y Greco- Resumen: "Entre trayectorias"Nicastro y Greco- Resumen: "Entre trayectorias"
Nicastro y Greco- Resumen: "Entre trayectorias"
 
Programa a alemanya final 2013
Programa a alemanya final 2013Programa a alemanya final 2013
Programa a alemanya final 2013
 
กิจกรรม Km กองบิน ๒๓
กิจกรรม Km กองบิน ๒๓กิจกรรม Km กองบิน ๒๓
กิจกรรม Km กองบิน ๒๓
 
The dangerous 2 vikilletra carta a julieta[1]
The dangerous 2 vikilletra carta a julieta[1]The dangerous 2 vikilletra carta a julieta[1]
The dangerous 2 vikilletra carta a julieta[1]
 
The dangerous 2 vikilletra carta a julieta[1]
The dangerous 2 vikilletra carta a julieta[1]The dangerous 2 vikilletra carta a julieta[1]
The dangerous 2 vikilletra carta a julieta[1]
 
กำหนดการตรวจมาตรฐาน สพ
กำหนดการตรวจมาตรฐาน สพกำหนดการตรวจมาตรฐาน สพ
กำหนดการตรวจมาตรฐาน สพ
 
Littlebird egy munkája
Littlebird egy munkájaLittlebird egy munkája
Littlebird egy munkája
 
Pc
PcPc
Pc
 
Doc pares ins doctor puigvert
Doc pares ins doctor puigvertDoc pares ins doctor puigvert
Doc pares ins doctor puigvert
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Design patterns in Ruby

  • 1. Design Patterns in Ruby @russolsen 1 Wednesday, July 25, 12
  • 4. Th ird & Me! 4 Wednesday, July 25, 12
  • 5. (magma) edward.og 5 Wednesday, July 25, 12
  • 6. FORTRAN Pascal BASIC C C++ Python Java Ruby Clojure 6 Wednesday, July 25, 12
  • 7. Design Patterns: 3 Things in 1 7 Wednesday, July 25, 12
  • 8. Philosophy of Good Design 8 Wednesday, July 25, 12
  • 9. Common Problems Common Solutions 9 Wednesday, July 25, 12
  • 10. Some Common Solutions 10 Wednesday, July 25, 12
  • 11. More @#$& Documents! 11 Wednesday, July 25, 12
  • 12. Templates & Strategies 12 Wednesday, July 25, 12
  • 13. Document def render render_title(@title) render_author(@author) ... end PlainDocument HtmlDocument def render_title(t) def render_title(t) end end def render_author(a) def render_author(a) end end Template Method 13 Wednesday, July 25, 12
  • 14. PlainRender def render(doc) puts doc.title Document puts “By #{doc.author}” ... end def render @renderer.render(self) end HtmlRenderer def render(doc) ... end Strategy 14 Wednesday, July 25, 12
  • 15. Separate Out Change 15 Wednesday, July 25, 12
  • 16. Think Interface NOT Implementation 16 Wednesday, July 25, 12
  • 17. Composition NOT Inheritance 17 Wednesday, July 25, 12
  • 18. Delegate! 18 Wednesday, July 25, 12
  • 19. Five In Five! 19 Wednesday, July 25, 12
  • 20. Client “Stand In” “Real Object” Do something with @real Do real stuff Stand In Meta Pattern 20 Wednesday, July 25, 12
  • 21. What If You Need Control? 21 Wednesday, July 25, 12
  • 22. Proxy! 22 Wednesday, July 25, 12
  • 23. Client ProxyDoc Document def render def render(doc) if allowed? puts doc.title @doc.render puts “By #{doc.author}” end ... end end Proxy 23 Wednesday, July 25, 12
  • 24. What If You Need More? 24 Wednesday, July 25, 12
  • 25. Decorate! 25 Wednesday, July 25, 12
  • 26. Client Decorator Document def to_japanese translate(@doc.paragraphs) end def render @doc.render end Decorator 26 Wednesday, July 25, 12
  • 27. What If You Need Less? 27 Wednesday, July 25, 12
  • 28. Facade! 28 Wednesday, July 25, 12
  • 29. Client EnterpriseDoc Facade 10,000 Complex methods def render @ent_doc.complex_stuff() end Facade 29 Wednesday, July 25, 12
  • 30. What If You Need Different? 30 Wednesday, July 25, 12
  • 31. Adapt! 31 Wednesday, July 25, 12
  • 32. Client Adapter Document def print def render @doc.render ... end end Adapter 32 Wednesday, July 25, 12
  • 33. What If You Need Little Bits? 33 Wednesday, July 25, 12
  • 34. Compose! 34 Wednesday, July 25, 12
  • 35. Document Client Document CompositeDoc def render @subdocs.each do |s| s.render end end Document Composite 35 Wednesday, July 25, 12
  • 36. Design Patterns are nothing but decent pre-loaded solutions to common problems. 36 Wednesday, July 25, 12
  • 37. They are worth your time because of they are solutions, but also because they are decent. 37 Wednesday, July 25, 12
  • 38. russ@russolsen.com @russolsen thinkrelevance.com 38 Wednesday, July 25, 12