SlideShare uma empresa Scribd logo
1 de 52
Baixar para ler offline
Decorator Decorator 
& & 
PresenterPresenter
By: Carlos Sánchez Pérez          madrid­rbBy: Carlos Sánchez Pérez          madrid­rb
Tidy VIEWSTidy VIEWS
WHO AM I?
Person.new(
NameName : 'Carlos Sánchez Pérez',
LoveLove : 'Web Dev ­ Ruby & Rails',
TwitterTwitter : '@carlossanchezp',
JobJob : 'ASPgems',
GithubGithub : 'carlossanchezp',
Blog Blog ::'carlossanchezperez.wordpress.com
'
)
Let me show you about my ideas, in my blog. 
I'll be there for you tomorrow....
The Problem
VIEWS: Responsibility Overload
FAT MODEL
 BIGGEST HELPERS
What's wrong with it?
app/views/users/show.html.erb
DECORATOR PRESENTER
PRESENTERS Pattern 
Tidy Views 
The idea of a Presenter was first introduced 
to the Rails community by Jay Fields in a 
series of blog articles in 2006 and 2007.
Rails Presenter Pattern Jay Fields
Wikipedia:Model–view–presenter
PRESENTER
● Presenters are also decorators.
 
● The presenters is their 
proximity to the view and live 
very close to the view layer. 
● In fact, they are meant to be a 
representation of the delegate 
object within the view.
● The main goal of presenters is 
to keep logic out of the view.
● Presenters maintain an object­
oriented approach to logic in 
the view.
MODEL
VIEW
My name is Presenter,
Can I help you?
This way, presenters act like decorators. 
Wrap a Rails model and aid in the presentation.   
app/views/users/show.html.rb
DECORATOR Pattern
Tidy Views 
DECORATOR
● Start needing logic in the view 
or start thinking about a helper 
method, you can implement a 
method on the decorator instead.
● Attach additional 
responsibilities to an object 
dynamically.
● A decorator changes an object's 
skin. 
Jeff Casimir's draper is a gem that embodies 
the pattern and also allows you to invoke 
Rails' view helpers by exposing the view 
context in your decorators.
CHANGE:  UserDecorator.find(params[:id]
App/views/users/show.html.erb
DECORATOR PRESENTER
PRESENTER
DECORATOR
How to share?
In a view with decorator 
and without decorator
DRAPPER
def helpers
Draper::ViewContext.current
end
alias_method :h, :helpers
Is there anything else?
Decorator
OTHER SIDE
Sending Notifications Using 
Decorators
CALLBACK
MODEL
SEND
“Single Responsibility Principle” 
MODEL
FIND USER
DECORATOR
CALLING METHOD 
DECORATOR
One more
Notifications
The same object diferent Render
Exhibit Pattern
EXHIBIT
● Exhibits are just decorators.
● Add some additional 
functionality.
● The additional functionality 
added will extend, but not 
disrupt.
● Introducing the Exhibit Pattern 
by Avdi Grimm in his book “Objects 
on Rails“.
Conclusion
The power of decorators 
LINKS
Decorator gem: Decorator gem: https://github.com/drapergem/draperhttps://github.com/drapergem/draper  
Objects In Rails Objects In Rails http://objectsonrails.com/http://objectsonrails.com/
http://blog.jayfields.com/2007/03/rails­presenter­pattern.htmlhttp://blog.jayfields.com/2007/03/rails­presenter­pattern.html
http://railscasts.com/episodes/286­draperhttp://railscasts.com/episodes/286­draper
Any questions?
Dedication to....
Thanks ASPgems and twitter people!!
THANKS A LOT!!
That's all folks!!
and
Thanks a lot for 
your attention 

Mais conteúdo relacionado

Destaque

Transparencias taller Python
Transparencias taller PythonTransparencias taller Python
Transparencias taller PythonSergio Soto
 
Conferencia Big Data en #MenorcaConnecta
Conferencia Big Data en #MenorcaConnectaConferencia Big Data en #MenorcaConnecta
Conferencia Big Data en #MenorcaConnectaSanti Camps
 
Big data amb Cassandra i Celery ##bbmnk
Big data amb Cassandra i Celery ##bbmnkBig data amb Cassandra i Celery ##bbmnk
Big data amb Cassandra i Celery ##bbmnkSanti Camps
 
A Folksonomy of styles, aka: other stylists also said and Subjective Influenc...
A Folksonomy of styles, aka: other stylists also said and Subjective Influenc...A Folksonomy of styles, aka: other stylists also said and Subjective Influenc...
A Folksonomy of styles, aka: other stylists also said and Subjective Influenc...Natalia Díaz Rodríguez
 
Knowing your garbage collector - PyCon Italy 2015
Knowing your garbage collector - PyCon Italy 2015Knowing your garbage collector - PyCon Italy 2015
Knowing your garbage collector - PyCon Italy 2015fcofdezc
 
Knowing your Garbage Collector / Python Madrid
Knowing your Garbage Collector / Python MadridKnowing your Garbage Collector / Python Madrid
Knowing your Garbage Collector / Python Madridfcofdezc
 
STM on PyPy
STM on PyPySTM on PyPy
STM on PyPyfcofdezc
 
#DataBeers: Inmersive Data Visualization con Oculus Rift
#DataBeers: Inmersive Data Visualization con Oculus Rift#DataBeers: Inmersive Data Visualization con Oculus Rift
#DataBeers: Inmersive Data Visualization con Oculus RiftOutliers Collective
 
Volunteering assistance to online geocoding services through a distributed kn...
Volunteering assistance to online geocoding services through a distributed kn...Volunteering assistance to online geocoding services through a distributed kn...
Volunteering assistance to online geocoding services through a distributed kn...José Pablo Gómez Barrón S.
 
TDD in the Web with Python and Django
TDD in the Web with Python and DjangoTDD in the Web with Python and Django
TDD in the Web with Python and DjangoCarlos Ble
 
PyQgis gpul-lab Univerisity of A Coruña 20160413
PyQgis gpul-lab Univerisity of A Coruña 20160413PyQgis gpul-lab Univerisity of A Coruña 20160413
PyQgis gpul-lab Univerisity of A Coruña 20160413Luigi Pirelli
 

Destaque (20)

Python and MongoDB
Python and MongoDB Python and MongoDB
Python and MongoDB
 
Transparencias taller Python
Transparencias taller PythonTransparencias taller Python
Transparencias taller Python
 
Conferencia Big Data en #MenorcaConnecta
Conferencia Big Data en #MenorcaConnectaConferencia Big Data en #MenorcaConnecta
Conferencia Big Data en #MenorcaConnecta
 
Big data amb Cassandra i Celery ##bbmnk
Big data amb Cassandra i Celery ##bbmnkBig data amb Cassandra i Celery ##bbmnk
Big data amb Cassandra i Celery ##bbmnk
 
Zotero
ZoteroZotero
Zotero
 
10 cosas de rails que deberías saber
10 cosas de rails que deberías saber10 cosas de rails que deberías saber
10 cosas de rails que deberías saber
 
A Folksonomy of styles, aka: other stylists also said and Subjective Influenc...
A Folksonomy of styles, aka: other stylists also said and Subjective Influenc...A Folksonomy of styles, aka: other stylists also said and Subjective Influenc...
A Folksonomy of styles, aka: other stylists also said and Subjective Influenc...
 
Knowing your garbage collector - PyCon Italy 2015
Knowing your garbage collector - PyCon Italy 2015Knowing your garbage collector - PyCon Italy 2015
Knowing your garbage collector - PyCon Italy 2015
 
Knowing your Garbage Collector / Python Madrid
Knowing your Garbage Collector / Python MadridKnowing your Garbage Collector / Python Madrid
Knowing your Garbage Collector / Python Madrid
 
STM on PyPy
STM on PyPySTM on PyPy
STM on PyPy
 
Madrid SPARQL handson
Madrid SPARQL handsonMadrid SPARQL handson
Madrid SPARQL handson
 
#DataBeers: Inmersive Data Visualization con Oculus Rift
#DataBeers: Inmersive Data Visualization con Oculus Rift#DataBeers: Inmersive Data Visualization con Oculus Rift
#DataBeers: Inmersive Data Visualization con Oculus Rift
 
Volunteering assistance to online geocoding services through a distributed kn...
Volunteering assistance to online geocoding services through a distributed kn...Volunteering assistance to online geocoding services through a distributed kn...
Volunteering assistance to online geocoding services through a distributed kn...
 
TDD in the Web with Python and Django
TDD in the Web with Python and DjangoTDD in the Web with Python and Django
TDD in the Web with Python and Django
 
Presentacion scraping
Presentacion scrapingPresentacion scraping
Presentacion scraping
 
Grunt.js introduction
Grunt.js introductionGrunt.js introduction
Grunt.js introduction
 
PyQgis gpul-lab Univerisity of A Coruña 20160413
PyQgis gpul-lab Univerisity of A Coruña 20160413PyQgis gpul-lab Univerisity of A Coruña 20160413
PyQgis gpul-lab Univerisity of A Coruña 20160413
 
Charla mspba
Charla mspbaCharla mspba
Charla mspba
 
Guía de Python
Guía de Python Guía de Python
Guía de Python
 
Bucles con Scratch
Bucles con ScratchBucles con Scratch
Bucles con Scratch
 

Último

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.pdfkalichargn70th171
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
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.comFatema Valibhai
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
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...panagenda
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 

Último (20)

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
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
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
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
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...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 

Tidy vews, decorator and presenter