SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
PRESENTERS 
with a guest appearance from decorators
HI 
• tomridge2@gmail.com 
• @tjridge 
• github.com/ridget
LETS BUILD AN APP
VIEW RELATED LOGIC 
• welp
LETS PUT IT IN A HELPER!
HELPERS AREN’T AWESOME 
• at least for this task 
• they share a global namespace 
• aren’t a very oo way of solving the problem 
• great for shared logic that doesn't relate to the 
object. Use sparingly
I KNOW MODELS! 
• also nope 
• All these if conditions relate to the display of data 
• Don’t overload your model with that level of 
responsibility
ENTER PRESENTERS 
• Presenters are a simple class with knowledge of 
the model and the view. 
• Not a stretch to call them a ViewModel
PURPOSE 
• Presenters help to achieve adherence to SRP 
• A Presenter’s purpose is a decorator who has the 
job of massaging the decorated object into a ui/ 
view friendly manner.
DECORATOR? 
• Taking one object and adding, replacing or 
extending its behaviour, whilst allowing access to 
the underlying objects methods.
PRESENTERS VS DECORATORS 
• A decorator isn’t always a presenter, but a 
presenter is always likely to be a decorator.
END RESULT 
• This is more in line with a decorator approach 
• We just delegate to the underlying object
MULTIPLE OBJECTS? 
• ensure you delegate methods to the underlying 
objects
MULTIPLE RECORDS? 
• Just create a wrap method to instantiate your 
presenter/decorator across multiple records.
OTHER OPTIONS? 
• Draper 
• Great for when things start getting more 
complex
OTHER VALUE POINTS 
• Easy-ish to test 
• less conditionals in your views 
• happier designers/front end developers
CONS 
• More objects == harder to learn the codebase 
• Don’t introduce them until you need to.
GREAT RESOURCES 
• Railscasts - draper and presenters from scratch 
(pro) 
• http://new-bamboo.co.uk/blog/2013/04/17/rails-presenters- 
skinny-everything 
• http://robertomurray.co.uk/blog/2014/decorators-presenters- 
delegators-rails/
QUESTIONS?

Weitere ähnliche Inhalte

Ähnlich wie Rails Presenters

Design Pattern Zoology
Design Pattern ZoologyDesign Pattern Zoology
Design Pattern Zoology
Josh Adell
 

Ähnlich wie Rails Presenters (20)

Design Pattern Zoology
Design Pattern ZoologyDesign Pattern Zoology
Design Pattern Zoology
 
Software development fundamentals
Software development fundamentalsSoftware development fundamentals
Software development fundamentals
 
Future Friendly Style Guides
Future Friendly Style GuidesFuture Friendly Style Guides
Future Friendly Style Guides
 
Objectify Your Code
Objectify Your CodeObjectify Your Code
Objectify Your Code
 
A Future Friendly Workflow
A Future Friendly WorkflowA Future Friendly Workflow
A Future Friendly Workflow
 
The Design Fortress: Boosting Design Productivity and Creativity in an Agile ...
The Design Fortress: Boosting Design Productivity and Creativity in an Agile ...The Design Fortress: Boosting Design Productivity and Creativity in an Agile ...
The Design Fortress: Boosting Design Productivity and Creativity in an Agile ...
 
The 360 Developer
The 360 DeveloperThe 360 Developer
The 360 Developer
 
How to ensure a long life span for a website (WPHelsinki 2.11.2016)
How to ensure a long life span for a website (WPHelsinki 2.11.2016)How to ensure a long life span for a website (WPHelsinki 2.11.2016)
How to ensure a long life span for a website (WPHelsinki 2.11.2016)
 
How to ensure a long life span for a website?
How to ensure a long life span for a website?How to ensure a long life span for a website?
How to ensure a long life span for a website?
 
Creating a Great Portfolio Site
Creating a Great Portfolio SiteCreating a Great Portfolio Site
Creating a Great Portfolio Site
 
Beyond the rails way
Beyond the rails wayBeyond the rails way
Beyond the rails way
 
CPP16 - Object Design
CPP16 - Object DesignCPP16 - Object Design
CPP16 - Object Design
 
Planning Patterns for Agile Testers
Planning Patterns for Agile TestersPlanning Patterns for Agile Testers
Planning Patterns for Agile Testers
 
Untangling - fall2017 - week 7
Untangling - fall2017 - week 7Untangling - fall2017 - week 7
Untangling - fall2017 - week 7
 
Draper - Visnupriya - spriteXchange
Draper - Visnupriya - spriteXchangeDraper - Visnupriya - spriteXchange
Draper - Visnupriya - spriteXchange
 
Exhibits and Presenters
Exhibits and PresentersExhibits and Presenters
Exhibits and Presenters
 
Decorator Pattern
Decorator PatternDecorator Pattern
Decorator Pattern
 
Colin sullivan successful-project-presentation
Colin sullivan successful-project-presentationColin sullivan successful-project-presentation
Colin sullivan successful-project-presentation
 
Create Your Own Starter Files
Create Your Own Starter FilesCreate Your Own Starter Files
Create Your Own Starter Files
 
Designing for Everybody Workshop
Designing for Everybody WorkshopDesigning for Everybody Workshop
Designing for Everybody Workshop
 

Kürzlich hochgeladen

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 

Kürzlich hochgeladen (20)

Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 

Rails Presenters

  • 1. PRESENTERS with a guest appearance from decorators
  • 2. HI • tomridge2@gmail.com • @tjridge • github.com/ridget
  • 5. LETS PUT IT IN A HELPER!
  • 6.
  • 7. HELPERS AREN’T AWESOME • at least for this task • they share a global namespace • aren’t a very oo way of solving the problem • great for shared logic that doesn't relate to the object. Use sparingly
  • 8. I KNOW MODELS! • also nope • All these if conditions relate to the display of data • Don’t overload your model with that level of responsibility
  • 9. ENTER PRESENTERS • Presenters are a simple class with knowledge of the model and the view. • Not a stretch to call them a ViewModel
  • 10. PURPOSE • Presenters help to achieve adherence to SRP • A Presenter’s purpose is a decorator who has the job of massaging the decorated object into a ui/ view friendly manner.
  • 11. DECORATOR? • Taking one object and adding, replacing or extending its behaviour, whilst allowing access to the underlying objects methods.
  • 12. PRESENTERS VS DECORATORS • A decorator isn’t always a presenter, but a presenter is always likely to be a decorator.
  • 13. END RESULT • This is more in line with a decorator approach • We just delegate to the underlying object
  • 14. MULTIPLE OBJECTS? • ensure you delegate methods to the underlying objects
  • 15. MULTIPLE RECORDS? • Just create a wrap method to instantiate your presenter/decorator across multiple records.
  • 16. OTHER OPTIONS? • Draper • Great for when things start getting more complex
  • 17. OTHER VALUE POINTS • Easy-ish to test • less conditionals in your views • happier designers/front end developers
  • 18. CONS • More objects == harder to learn the codebase • Don’t introduce them until you need to.
  • 19. GREAT RESOURCES • Railscasts - draper and presenters from scratch (pro) • http://new-bamboo.co.uk/blog/2013/04/17/rails-presenters- skinny-everything • http://robertomurray.co.uk/blog/2014/decorators-presenters- delegators-rails/