SlideShare a Scribd company logo
Design Patterns in Rails 
A kweek case study
1. Introduction to the idea 
“Meet the parents”
Rupicon 2014 useful design patterns in rails
Old school
Old School 
- code smell 
- design smell
2. Challenge 
“Meet the Fockers”
Challenge 
- new design is a one step form vs the 3 step 
on the old design 
- save as draft implies no validations 
- preview will suffer from the new “draft” 
feature 
- publish will invoke validations
3. Where to start? 
??
SRP 
- Add Form - to update the model with data 
- Validation “Contract” - validate the model 
- Publish Facade 
- Presenter - to preview the event
Add Form 
Avdi Grimm describes form objects as boarder guards. They validate 
and verify that all data coming into the system is correct. 
Once the data moves past the checkpoint it is not checked again. 
- a single place to handle input coercion 
- virtus model 
- validations
Facade 
“The Facade Pattern is simply a formalization of the idea that if you 
cannot avoid complexity, then the next best thing to do is to isolate it, to 
keep it from contaminating your whole system” -- Russ Olsen 
- simplifies access to the object being wrapped or the subsystem 
- opposite to the decorator 
- they are not meant to hide anything
Facade
Facade and Friends 
- adapters exist to hide the fact that we are stuck using an object 
that has the wrong interface 
- a proxy stands between the user of an object and the object 
itself and somehow controls access to the object 
- decorators add functionality to an object
Validations on steroids 
Remember the contract? 
What if you want to validate certain contracts at a certain time? 
What if you don’t want to validate a contract at a certain point? 
- separate the contracts 
- group them together based on your needs 
- validate them…?
Validations on steroids 
Wikipedia says : The composite pattern describes that a group of 
objects is to be treated in the same way as a single instance of an object
Validations on steroids
Presenter 
Bordei Cristian 
- is a way to keep your view and controller logic 
as clean as possible by having a Ruby class serve 
as the interface between your model and the 
view/controller.
Presenter
Presenter
Presenter vs Helper 
Why not Helper you say? 
- have logic specific to your models that you need encapsulated 
- something you can test 
- something you can extend
Preview event 
- Saving something as a draft can 
be a b***h 
- To preview, you would need 
defaults
4. Conclusions 
“Little Fockers”
Conclusions 
- Facades are fun and easy but are not an excuse for adding 
features to a subsystem 
- If you want to make several types of coffee with different coffee 
machines, use a composite 
- Presenters make you think helpers are like a compliment that you 
don't want to give, but feel obligated to: "Yeah, I mean, well, you 
tried, and that's what counts, right?"
QUESTIONS?!

More Related Content

PDF
Rupicon 2014 Action pack
PDF
Rupicon 2014 Single table inheritance
PDF
Rupicon 2014 caching
PDF
Rupicon 2014 solid
PPTX
Design patterns
PDF
What’s Up, EDoc?!
PDF
ODSC West 2022 – Kitbashing in ML
PDF
26 story slicing techniques for any scrum team
Rupicon 2014 Action pack
Rupicon 2014 Single table inheritance
Rupicon 2014 caching
Rupicon 2014 solid
Design patterns
What’s Up, EDoc?!
ODSC West 2022 – Kitbashing in ML
26 story slicing techniques for any scrum team

Similar to Rupicon 2014 useful design patterns in rails (20)

PDF
Creating Stable Assignments
PPTX
DevOne - How to not fail with Azure
PPTX
Techniques to decompose a user story Techniques
PDF
Creating Realistic Unit Tests with Testcontainers
PPTX
Shut Up And Eat Your Veg
PDF
2019 StartIT - Boosting your performance with Blackfire
PDF
PVS-Studio and CppCat: An Interview with Andrey Karpov, the Project CTO and D...
PPTX
ASP .NET MVC - best practices
PPTX
No more Three Tier - A path to a better code for Cloud and Azure
PPT
Asp netmvc
PDF
iOS development best practices
PPTX
Let us understand design pattern
PDF
Use Case Patterns for LLM Applications (1).pdf
TXT
why c++11?
PDF
Understanding Complexity of Organizational and System Dynamics
PDF
The Art Of Performance Tuning - with presenter notes!
PPTX
L03 Design Patterns
PDF
10 Ways To Improve Your Code
PDF
We continue checking Microsoft projects: analysis of PowerShell
PDF
Fast and effective analysis of architecture diagrams
Creating Stable Assignments
DevOne - How to not fail with Azure
Techniques to decompose a user story Techniques
Creating Realistic Unit Tests with Testcontainers
Shut Up And Eat Your Veg
2019 StartIT - Boosting your performance with Blackfire
PVS-Studio and CppCat: An Interview with Andrey Karpov, the Project CTO and D...
ASP .NET MVC - best practices
No more Three Tier - A path to a better code for Cloud and Azure
Asp netmvc
iOS development best practices
Let us understand design pattern
Use Case Patterns for LLM Applications (1).pdf
why c++11?
Understanding Complexity of Organizational and System Dynamics
The Art Of Performance Tuning - with presenter notes!
L03 Design Patterns
10 Ways To Improve Your Code
We continue checking Microsoft projects: analysis of PowerShell
Fast and effective analysis of architecture diagrams
Ad

More from rupicon (6)

PDF
RSpec matchers
PDF
DIY Cartography
PDF
Dr. PostGIS or: How I Learned to Stop Worrying and Love the Docs
PDF
Are you tougher than a boy/girl scout?
PDF
Johnny Cache
PDF
U wont bleev wut dis code doez
RSpec matchers
DIY Cartography
Dr. PostGIS or: How I Learned to Stop Worrying and Love the Docs
Are you tougher than a boy/girl scout?
Johnny Cache
U wont bleev wut dis code doez
Ad

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Cloud computing and distributed systems.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Electronic commerce courselecture one. Pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Big Data Technologies - Introduction.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Approach and Philosophy of On baking technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Encapsulation_ Review paper, used for researhc scholars
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Building Integrated photovoltaic BIPV_UPV.pdf
A Presentation on Artificial Intelligence
gpt5_lecture_notes_comprehensive_20250812015547.pdf
sap open course for s4hana steps from ECC to s4
20250228 LYD VKU AI Blended-Learning.pptx
Encapsulation theory and applications.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Cloud computing and distributed systems.
Dropbox Q2 2025 Financial Results & Investor Presentation
Electronic commerce courselecture one. Pdf
A comparative analysis of optical character recognition models for extracting...
Machine learning based COVID-19 study performance prediction
Diabetes mellitus diagnosis method based random forest with bat algorithm
Big Data Technologies - Introduction.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Approach and Philosophy of On baking technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx

Rupicon 2014 useful design patterns in rails

  • 1. Design Patterns in Rails A kweek case study
  • 2. 1. Introduction to the idea “Meet the parents”
  • 5. Old School - code smell - design smell
  • 6. 2. Challenge “Meet the Fockers”
  • 7. Challenge - new design is a one step form vs the 3 step on the old design - save as draft implies no validations - preview will suffer from the new “draft” feature - publish will invoke validations
  • 8. 3. Where to start? ??
  • 9. SRP - Add Form - to update the model with data - Validation “Contract” - validate the model - Publish Facade - Presenter - to preview the event
  • 10. Add Form Avdi Grimm describes form objects as boarder guards. They validate and verify that all data coming into the system is correct. Once the data moves past the checkpoint it is not checked again. - a single place to handle input coercion - virtus model - validations
  • 11. Facade “The Facade Pattern is simply a formalization of the idea that if you cannot avoid complexity, then the next best thing to do is to isolate it, to keep it from contaminating your whole system” -- Russ Olsen - simplifies access to the object being wrapped or the subsystem - opposite to the decorator - they are not meant to hide anything
  • 13. Facade and Friends - adapters exist to hide the fact that we are stuck using an object that has the wrong interface - a proxy stands between the user of an object and the object itself and somehow controls access to the object - decorators add functionality to an object
  • 14. Validations on steroids Remember the contract? What if you want to validate certain contracts at a certain time? What if you don’t want to validate a contract at a certain point? - separate the contracts - group them together based on your needs - validate them…?
  • 15. Validations on steroids Wikipedia says : The composite pattern describes that a group of objects is to be treated in the same way as a single instance of an object
  • 17. Presenter Bordei Cristian - is a way to keep your view and controller logic as clean as possible by having a Ruby class serve as the interface between your model and the view/controller.
  • 20. Presenter vs Helper Why not Helper you say? - have logic specific to your models that you need encapsulated - something you can test - something you can extend
  • 21. Preview event - Saving something as a draft can be a b***h - To preview, you would need defaults
  • 23. Conclusions - Facades are fun and easy but are not an excuse for adding features to a subsystem - If you want to make several types of coffee with different coffee machines, use a composite - Presenters make you think helpers are like a compliment that you don't want to give, but feel obligated to: "Yeah, I mean, well, you tried, and that's what counts, right?"