SlideShare a Scribd company logo
DECORATOR & PRESENTER
DESIGN PATTERN
@DonSchado | 21.05.2014
WHY?
Because your controllers become bloated	

and logic begins to creep into your views (templates)
implement procedural helpers or adding view related bulk to your models?
Solutions?
implement procedural helpers or adding view related bulk to your models?
Solutions?
helpers are shit making fat models even fatter?

No class should be fat. Ever.
Why are helpers shit?
http://nicksda.apotomo.de/2011/10/rails-misapprehensions-helpers-are-shit/
„all helpers are mixed into the view
automatically (…) [and are] globally available“
„There is nothing wrong with having those little
helpers in your view.What I don’t like is that
they are called without an obvious receiver –
they look and feel like functions.This is wrong.“
Why are helpers shit?
http://blog.steveklabnik.com/posts/2011-09-09-better-ruby-presenters
„No seriously, helpers suck“
„Why is it in Ruby that everything is an
object, even integers, yet as soon as we
need to format a date, we all turn into
Dijkstra and bust out structured
programming?“
DECORATOR
Decorator pattern (also known as wrapper) is a design pattern that
allows to dynamically add behavior to an individual object.
can be used on it’s own 	

or wrapped by decorator
each decorator HAS_A (wraps)	

a component (holds a reference)
(composition)(inheritance)
The decorator wraps the model, and deals only with presentational concerns. 	

In the controller, you decorate the article before handing it off to the view
https://github.com/drapergem/draper
Draper: View Models for Rails
Draper adds an object-oriented layer of
presentation logic to your Rails application
Decorator & Presenter Design Pattern
Decorator & Presenter Design Pattern
Decorator & Presenter Design Pattern
PRESENTER
A presenter is a special case of the "Decorator design pattern".
http://sokolmichael.com/posts/2012-01-14-model-view-controller-presenter-better-separation-of-concern
MVCP - Better Separation of Concern
http://blog.jayfields.com/2007/03/rails-presenter-pattern.html
Presenter was inspired by the various GUI
patterns documented by Martin Fowler.
An architecture that uses the Presenter
pattern provides view specific data as
attributes of an instance of the
Presenter.The Presenter's state is an
aggregation of model and user entered data.
Decorator & Presenter Design Pattern
Decorator & Presenter Design Pattern
7 Patterns to Refactor Fat ActiveRecord Models
http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/
Service Objects
Value Objects
Form Objects
Query Objects
View Objects
Policy Objects
Decorators
further reading:
thx!(and have fun refactoring all the fat classes)

More Related Content

PDF
PostgreSQL Tutorial for Beginners | Edureka
PDF
Row level security
PPTX
Gof design patterns
PPTX
Decorator Pattern
PPTX
Design pattern-presentation
PDF
The Object Oriented Database System Manifesto
PDF
Neo4j Generative AI workshop at GraphSummit London 14 Nov 2023.pdf
PPTX
Software Architecture
PostgreSQL Tutorial for Beginners | Edureka
Row level security
Gof design patterns
Decorator Pattern
Design pattern-presentation
The Object Oriented Database System Manifesto
Neo4j Generative AI workshop at GraphSummit London 14 Nov 2023.pdf
Software Architecture

What's hot (20)

PPTX
Design Patterns - 01 Introduction and Decorator Pattern
PPT
Facade pattern
PPTX
Service Oriented Architecture (SOA)
PPT
MySql slides (ppt)
PPTX
Package Diagram
PDF
An Introduction to Software Architecture
PPTX
Domain Driven Design
PPTX
Decorator design pattern
PPT
3 Tier Architecture
PPT
Software Design Patterns
PPTX
Design Patterns - Abstract Factory Pattern
PDF
Oracle Analytics Cloud のご紹介【2021年3月版】
PPT
Class diagram presentation
PDF
Introduction to Design Pattern
PDF
第18回しゃちほこオラクル俱楽部
PDF
Oracle Cloud Infrastructure:2022年1月度サービス・アップデート
PPTX
Data abstraction in DBMS
PPT
Sequence diagrams
PPTX
Facade pattern presentation(.pptx)
PDF
Discover Neo4j Aura_ The Future of Graph Database-as-a-Service Workshop_3.13.24
Design Patterns - 01 Introduction and Decorator Pattern
Facade pattern
Service Oriented Architecture (SOA)
MySql slides (ppt)
Package Diagram
An Introduction to Software Architecture
Domain Driven Design
Decorator design pattern
3 Tier Architecture
Software Design Patterns
Design Patterns - Abstract Factory Pattern
Oracle Analytics Cloud のご紹介【2021年3月版】
Class diagram presentation
Introduction to Design Pattern
第18回しゃちほこオラクル俱楽部
Oracle Cloud Infrastructure:2022年1月度サービス・アップデート
Data abstraction in DBMS
Sequence diagrams
Facade pattern presentation(.pptx)
Discover Neo4j Aura_ The Future of Graph Database-as-a-Service Workshop_3.13.24
Ad

Similar to Decorator & Presenter Design Pattern (20)

PDF
"Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ...
PDF
Gof design pattern
PPTX
Onion Architecture with S#arp
PPS
Design Patterns For 70% Of Programmers In The World
PDF
Make your Backbone Application dance
PDF
I Heard React Was Good
KEY
Zend Framework Modular Project Setup
PPT
Zend_Layout & Zend_View Enhancements
PPTX
Angular js workshop
PDF
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
PPTX
Design Pattern - MVC, MVP and MVVM
PPTX
MVC & backbone.js
KEY
Architecting Drupal Modules - Report from the frontlines
PPT
MVC Demystified: Essence of Ruby on Rails
PDF
Action-Domain-Responder: A Refinement of MVC
PPTX
Applied patterns in the project
PDF
Domas monkus drupal module development
PPTX
Draper - Visnupriya - spriteXchange
PDF
Introducing Ruby/MVC/RoR
PDF
jQquerysummit - Large-scale JavaScript Application Architecture
"Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ...
Gof design pattern
Onion Architecture with S#arp
Design Patterns For 70% Of Programmers In The World
Make your Backbone Application dance
I Heard React Was Good
Zend Framework Modular Project Setup
Zend_Layout & Zend_View Enhancements
Angular js workshop
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Design Pattern - MVC, MVP and MVVM
MVC & backbone.js
Architecting Drupal Modules - Report from the frontlines
MVC Demystified: Essence of Ruby on Rails
Action-Domain-Responder: A Refinement of MVC
Applied patterns in the project
Domas monkus drupal module development
Draper - Visnupriya - spriteXchange
Introducing Ruby/MVC/RoR
jQquerysummit - Large-scale JavaScript Application Architecture
Ad

More from DonSchado (7)

PDF
Ruby MVC from scratch with Rack
PDF
The return of an old enemy
PDF
Rails Girls: Programming, Web Applications and Ruby on Rails
PDF
Ruby's require, autoload and load methods
PDF
A taste of Computer Science
PDF
Mutation testing with the mutant gem
PDF
Rails - How does it work?
Ruby MVC from scratch with Rack
The return of an old enemy
Rails Girls: Programming, Web Applications and Ruby on Rails
Ruby's require, autoload and load methods
A taste of Computer Science
Mutation testing with the mutant gem
Rails - How does it work?

Recently uploaded (20)

PDF
MIND Revenue Release Quarter 2 2025 Press Release
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Spectroscopy.pptx food analysis technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
cuic standard and advanced reporting.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
KodekX | Application Modernization Development
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
MIND Revenue Release Quarter 2 2025 Press Release
The AUB Centre for AI in Media Proposal.docx
Spectroscopy.pptx food analysis technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Machine learning based COVID-19 study performance prediction
Dropbox Q2 2025 Financial Results & Investor Presentation
cuic standard and advanced reporting.pdf
Approach and Philosophy of On baking technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation_ Review paper, used for researhc scholars
Chapter 3 Spatial Domain Image Processing.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Review of recent advances in non-invasive hemoglobin estimation
Programs and apps: productivity, graphics, security and other tools
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Understanding_Digital_Forensics_Presentation.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
KodekX | Application Modernization Development
Advanced methodologies resolving dimensionality complications for autism neur...

Decorator & Presenter Design Pattern

  • 1. DECORATOR & PRESENTER DESIGN PATTERN @DonSchado | 21.05.2014
  • 3. Because your controllers become bloated and logic begins to creep into your views (templates)
  • 4. implement procedural helpers or adding view related bulk to your models? Solutions?
  • 5. implement procedural helpers or adding view related bulk to your models? Solutions? helpers are shit making fat models even fatter?
 No class should be fat. Ever.
  • 6. Why are helpers shit? http://nicksda.apotomo.de/2011/10/rails-misapprehensions-helpers-are-shit/ „all helpers are mixed into the view automatically (…) [and are] globally available“ „There is nothing wrong with having those little helpers in your view.What I don’t like is that they are called without an obvious receiver – they look and feel like functions.This is wrong.“
  • 7. Why are helpers shit? http://blog.steveklabnik.com/posts/2011-09-09-better-ruby-presenters „No seriously, helpers suck“ „Why is it in Ruby that everything is an object, even integers, yet as soon as we need to format a date, we all turn into Dijkstra and bust out structured programming?“
  • 9. Decorator pattern (also known as wrapper) is a design pattern that allows to dynamically add behavior to an individual object. can be used on it’s own or wrapped by decorator each decorator HAS_A (wraps) a component (holds a reference) (composition)(inheritance)
  • 10. The decorator wraps the model, and deals only with presentational concerns. In the controller, you decorate the article before handing it off to the view
  • 11. https://github.com/drapergem/draper Draper: View Models for Rails Draper adds an object-oriented layer of presentation logic to your Rails application
  • 16. A presenter is a special case of the "Decorator design pattern". http://sokolmichael.com/posts/2012-01-14-model-view-controller-presenter-better-separation-of-concern MVCP - Better Separation of Concern
  • 17. http://blog.jayfields.com/2007/03/rails-presenter-pattern.html Presenter was inspired by the various GUI patterns documented by Martin Fowler. An architecture that uses the Presenter pattern provides view specific data as attributes of an instance of the Presenter.The Presenter's state is an aggregation of model and user entered data.
  • 20. 7 Patterns to Refactor Fat ActiveRecord Models http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/ Service Objects Value Objects Form Objects Query Objects View Objects Policy Objects Decorators further reading:
  • 21. thx!(and have fun refactoring all the fat classes)