SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler 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

Mais conteúdo relacionado

Destaque (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
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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...
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
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
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
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...
 

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