SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Downloaden Sie, um offline zu lesen
Patterns in Rails
Cory Foy
@cory_foy
cory@8thlight.com
www.8thlight.com
Friday, June 21, 13
Patterns
Friday, June 21, 13
Friday, June 21, 13
“The specific patterns out of which a building or a town
is made may be alive or dead. To the extent they are
alive, they let our inner forces loose, and set us free; but
when they are dead, they keep us locked in inner
conflict.”
Christopher Alexander - “The Timeless Way of Building”
Friday, June 21, 13
“And it turns out...behind all processes which allow us to
make buildings live, there is a single common process.
But though this method is precise, it cannot be used
mechanically.
Indeed it turns out, in the end, that what this method
does is simply free us from all method.”
Christopher Alexander - “The Timeless Way of Building”
Friday, June 21, 13
“...we have so far beset ourselves with rules, and
concepts, and ideas of what must be done to make a
building or a town alive, that we have become afraid of
what will happen naturally, and convinced that we must
work within a “system” and with “methods” since
without them our surroundings will come tumbling down
in chaos.”
Christopher Alexander - “The Timeless Way of Building”
Friday, June 21, 13
Naming something the name of a pattern does
not make it that pattern
Friday, June 21, 13
Friday, June 21, 13
Pattern Name
Intent
Motivation
Consequences
Implementation
Elements of a pattern
Friday, June 21, 13
Rails
Friday, June 21, 13
Friday, June 21, 13
“From the beginning, the Rails framework
turned web development on its head with
the insight that the vast majority of time
spent on projects amounted to meaningless
sit-ups.
Instead of having the time to think your
domain-specific code, you’d spend the first
few weeks of a project deciding meaningless
details.”
- Yahuda Katz, The Rails 3 Way
Friday, June 21, 13
“[Rails is] not a blank slate equally tolerant
of every kind of expression. On the
contrary, it trades that flexibility for the
convenience of ‘what most people need
most of the time to do most things’”
- David Heinmeier Hansson -
The Rails 3 Way
Friday, June 21, 13
Not to be confused with Ruby
(programming language).
- Wikipedia
Friday, June 21, 13
Ruby on Rails, often simply Rails, is an open
source web application framework which
runs on the Ruby programming language. It
is a full-stack framework: it allows creating
pages and applications that gather
information from the web server, talk to or
query the database, and render templates
out of the box. As a result, Rails features a
routing system that is independent of the
web server.
Friday, June 21, 13
Ruby on Rails emphasizes the use of well-
known software engineering patterns and
principles, such as active record pattern,
convention over configuration (CoC), don't
repeat yourself (DRY), and model-view-
controller (MVC).
Friday, June 21, 13
REST
Routing
Validations
Controllers
Action View
Action Mailer
Active Record
Authentication
Session Management
Background Processing
Caching and Performance
Extending Rails with Plugins
Friday, June 21, 13
Model-View Controller
Active Record
Template View
Front Controller
Single Table Inheritance
Friday, June 21, 13
Friday, June 21, 13
Pattern Name
Intent
Motivation
Consequences
Implementation
Elements of a pattern
Friday, June 21, 13
Name Model-View Controller
Intent
Separate the presentation of the model
from the view, and separate the wiring
of the model to the view
Motivation
A web application which has many
models that need to be interacted with
by end users
Implementation
View, Model and Controller should be
in separate classes.View should depend
on model, but not vice versa
Consequences
May be overkill for simple systems
where the model has very little
behavior
Friday, June 21, 13
Friday, June 21, 13
Name Front Controller
Intent
Consolidate request handling by
channeling requests through a single
handler object
Motivation
Centralize the logic and handling for the
many things that need to happen for a
complex web site
Implementation
Create a class to handle all calls for a
web site, and determines the correct
classes to dispatch the request to
Consequences
More complicated than a Page
Controller. Can turn into a God class
Friday, June 21, 13
/rails/actionpack/lib/action_dispatch/routing/route_set.rb
Friday, June 21, 13
Name Mapper
Intent
Set up communications between two
subsystems that need to stay ignorant
of each other
Motivation
Allow two independent systems to be able
to talk to each other without them being
dependent on each other or the mapper
Implementation
Initialize the mapper (maybe using a
Front Controller) and configure the
communication between systems
Consequences
May be difficult to initialize and
configure the mapper since the
subsystems can’t know about it
Friday, June 21, 13
/rails/actionpack/lib/action_dispatch/routing/route_set.rb
Friday, June 21, 13
Name Active Record
Intent
An object that wraps a row in a
database table, encapsulates the access,
and adds domain logic on that data
Motivation
Simplify the need to persist data by
putting the data access logic in the
domain object
Implementation
Each class is responsible for saving and
loading to the database, and for any
domain logic that acts on the data
Consequences
Best when domain logic isn’t too complex,
and when model corresponds directly to the
database table. Couples system to DB
Friday, June 21, 13
Friday, June 21, 13
Friday, June 21, 13
Friday, June 21, 13
Name Single Table Inheritance
Intent
Represent an inheritance hierarchy of classes
as a single table that has columns for all of
the fields of the classes
Motivation
Minimize the number of joins when
representing an inheritance structure in
a relational database
Implementation
A single table contains all of the fields
for the subclasses. Classes may or may
not use all of the fields.
Consequences
Since not all columns are used, may be
confusing. May cause large tables. Only
have a single namespace for fields.
Friday, June 21, 13
Friday, June 21, 13
Name TemplateView
Intent
Render information into HTML by
embedding markers in an HTML page
Motivation
Allow HTML pages to be created as if
they were static, but still be able to
insert dynamic data
Implementation
Embed placeholders into a static HTML
page when it’s written. Replace
placeholders with content at runtime.
Consequences
Easy to put complicated logic in the
view. Harder to test since generally
designed to work within a web server
Friday, June 21, 13
Friday, June 21, 13
Software is our craft TM
8th Light
Cory Foy (@cory_foy)
cory@8thlight.com
www.8thlight.com
Friday, June 21, 13

Weitere ähnliche Inhalte

Andere mochten auch

Kanban for DevOps
Kanban for DevOpsKanban for DevOps
Kanban for DevOpsCory Foy
 
Triangle.rb - How Secure is Your Rails Site, Anyway?
Triangle.rb - How Secure is Your Rails Site, Anyway?Triangle.rb - How Secure is Your Rails Site, Anyway?
Triangle.rb - How Secure is Your Rails Site, Anyway?Cory Foy
 
Scaling Agility
Scaling AgilityScaling Agility
Scaling AgilityCory Foy
 
Ruby and OO for Beginners
Ruby and OO for BeginnersRuby and OO for Beginners
Ruby and OO for BeginnersCory Foy
 
Collaborating with Customers using Innovation Game
Collaborating with Customers using Innovation GameCollaborating with Customers using Innovation Game
Collaborating with Customers using Innovation GameEnthiosys Inc
 
Scrum and kanban
Scrum and kanbanScrum and kanban
Scrum and kanbanAgileee
 
Ruby for C# Developers
Ruby for C# DevelopersRuby for C# Developers
Ruby for C# DevelopersCory Foy
 
Agile Roots: The Agile Mindset - Agility Across the Organization
Agile Roots: The Agile Mindset - Agility Across the OrganizationAgile Roots: The Agile Mindset - Agility Across the Organization
Agile Roots: The Agile Mindset - Agility Across the OrganizationCory Foy
 
Choosing Between Scrum and Kanban - TriAgile 2015
Choosing Between Scrum and Kanban - TriAgile 2015Choosing Between Scrum and Kanban - TriAgile 2015
Choosing Between Scrum and Kanban - TriAgile 2015Cory Foy
 
Code Katas
Code KatasCode Katas
Code KatasCory Foy
 
Stratgic Play - Doing the Right Thing at the Right Time
Stratgic Play - Doing the Right Thing at the Right TimeStratgic Play - Doing the Right Thing at the Right Time
Stratgic Play - Doing the Right Thing at the Right TimeCory Foy
 
Continuous Deployment and Testing Workshop from Better Software West
Continuous Deployment and Testing Workshop from Better Software WestContinuous Deployment and Testing Workshop from Better Software West
Continuous Deployment and Testing Workshop from Better Software WestCory Foy
 
Scrum vs Kanban - Implementing Agility at Scale
Scrum vs Kanban - Implementing Agility at ScaleScrum vs Kanban - Implementing Agility at Scale
Scrum vs Kanban - Implementing Agility at ScaleCory Foy
 
Scrum & Kanban for Social Games
Scrum & Kanban for Social GamesScrum & Kanban for Social Games
Scrum & Kanban for Social GamesWooga
 
Kanban boards step by step
Kanban boards step by stepKanban boards step by step
Kanban boards step by stepGiulio Roggero
 

Andere mochten auch (16)

Kanban for DevOps
Kanban for DevOpsKanban for DevOps
Kanban for DevOps
 
Triangle.rb - How Secure is Your Rails Site, Anyway?
Triangle.rb - How Secure is Your Rails Site, Anyway?Triangle.rb - How Secure is Your Rails Site, Anyway?
Triangle.rb - How Secure is Your Rails Site, Anyway?
 
Scaling Agility
Scaling AgilityScaling Agility
Scaling Agility
 
Ruby and OO for Beginners
Ruby and OO for BeginnersRuby and OO for Beginners
Ruby and OO for Beginners
 
Collaborating with Customers using Innovation Game
Collaborating with Customers using Innovation GameCollaborating with Customers using Innovation Game
Collaborating with Customers using Innovation Game
 
Scrum and kanban
Scrum and kanbanScrum and kanban
Scrum and kanban
 
Ruby for C# Developers
Ruby for C# DevelopersRuby for C# Developers
Ruby for C# Developers
 
Agile Roots: The Agile Mindset - Agility Across the Organization
Agile Roots: The Agile Mindset - Agility Across the OrganizationAgile Roots: The Agile Mindset - Agility Across the Organization
Agile Roots: The Agile Mindset - Agility Across the Organization
 
Choosing Between Scrum and Kanban - TriAgile 2015
Choosing Between Scrum and Kanban - TriAgile 2015Choosing Between Scrum and Kanban - TriAgile 2015
Choosing Between Scrum and Kanban - TriAgile 2015
 
Code Katas
Code KatasCode Katas
Code Katas
 
Stratgic Play - Doing the Right Thing at the Right Time
Stratgic Play - Doing the Right Thing at the Right TimeStratgic Play - Doing the Right Thing at the Right Time
Stratgic Play - Doing the Right Thing at the Right Time
 
Continuous Deployment and Testing Workshop from Better Software West
Continuous Deployment and Testing Workshop from Better Software WestContinuous Deployment and Testing Workshop from Better Software West
Continuous Deployment and Testing Workshop from Better Software West
 
Scrum vs Kanban - Implementing Agility at Scale
Scrum vs Kanban - Implementing Agility at ScaleScrum vs Kanban - Implementing Agility at Scale
Scrum vs Kanban - Implementing Agility at Scale
 
Scrum & Kanban for Social Games
Scrum & Kanban for Social GamesScrum & Kanban for Social Games
Scrum & Kanban for Social Games
 
Kanban boards step by step
Kanban boards step by stepKanban boards step by step
Kanban boards step by step
 
Design Thinking Method Cards
Design Thinking Method CardsDesign Thinking Method Cards
Design Thinking Method Cards
 

Ähnlich wie Patterns in Rails

Making the Switch, Part 1: Top 5 Things to Consider When Evaluating Drupal
Making the Switch, Part 1: Top 5 Things to Consider When Evaluating DrupalMaking the Switch, Part 1: Top 5 Things to Consider When Evaluating Drupal
Making the Switch, Part 1: Top 5 Things to Consider When Evaluating DrupalAcquia
 
Simple Knowledge Organization System (SKOS) in the Context of Semantic Web De...
Simple Knowledge Organization System (SKOS) in the Context of Semantic Web De...Simple Knowledge Organization System (SKOS) in the Context of Semantic Web De...
Simple Knowledge Organization System (SKOS) in the Context of Semantic Web De...gardensofmeaning
 
Drupal camp atlanta 2013 mobile first
Drupal camp atlanta 2013 mobile firstDrupal camp atlanta 2013 mobile first
Drupal camp atlanta 2013 mobile firsttobbyhagler
 
Web Summer Camp Keynote
Web Summer Camp KeynoteWeb Summer Camp Keynote
Web Summer Camp KeynoteRachel Andrew
 
Intro to-html-backbone-angular
Intro to-html-backbone-angularIntro to-html-backbone-angular
Intro to-html-backbone-angularzonathen
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneDeepu S Nath
 
Exploiting Semantic Web Techniques For Representing And Utilising
Exploiting Semantic Web Techniques For Representing And UtilisingExploiting Semantic Web Techniques For Representing And Utilising
Exploiting Semantic Web Techniques For Representing And UtilisingOwen Sacco
 
Werfel, j. 2006: extended stigmergy in collective construction.in life intel...
Werfel, j. 2006: extended stigmergy in collective construction.in life  intel...Werfel, j. 2006: extended stigmergy in collective construction.in life  intel...
Werfel, j. 2006: extended stigmergy in collective construction.in life intel...ArchiLab 7
 
Seattle Data Geeks: Hadoop and Beyond
Seattle Data Geeks: Hadoop and BeyondSeattle Data Geeks: Hadoop and Beyond
Seattle Data Geeks: Hadoop and BeyondPaco Nathan
 
Measurement and modeling of the web and related data sets
Measurement and modeling of the web and related data setsMeasurement and modeling of the web and related data sets
Measurement and modeling of the web and related data setsMark J. Feldman
 
Beyond the Page
Beyond the PageBeyond the Page
Beyond the Pagegsmith
 
OMG Callimachus Demo 20120322 small
OMG Callimachus Demo 20120322 smallOMG Callimachus Demo 20120322 small
OMG Callimachus Demo 20120322 small3 Round Stones
 
Big table presentation-final
Big table presentation-finalBig table presentation-final
Big table presentation-finalYunming Zhang
 
Social Network Analysis Introduction including Data Structure Graph overview.
Social Network Analysis Introduction including Data Structure Graph overview. Social Network Analysis Introduction including Data Structure Graph overview.
Social Network Analysis Introduction including Data Structure Graph overview. Doug Needham
 
Building Next-Gen Web Applications with the Spring 3 Web Stack
Building Next-Gen Web Applications with the Spring 3 Web StackBuilding Next-Gen Web Applications with the Spring 3 Web Stack
Building Next-Gen Web Applications with the Spring 3 Web StackJeremy Grelle
 
CloudDesk - Cloud operating system
CloudDesk - Cloud operating systemCloudDesk - Cloud operating system
CloudDesk - Cloud operating systemRajesh Hegde
 
Getting Started with Meteor
Getting Started with MeteorGetting Started with Meteor
Getting Started with MeteorMichael Redlich
 

Ähnlich wie Patterns in Rails (20)

Making the Switch, Part 1: Top 5 Things to Consider When Evaluating Drupal
Making the Switch, Part 1: Top 5 Things to Consider When Evaluating DrupalMaking the Switch, Part 1: Top 5 Things to Consider When Evaluating Drupal
Making the Switch, Part 1: Top 5 Things to Consider When Evaluating Drupal
 
NoSQL Basics - A Quick Tour
NoSQL Basics - A Quick TourNoSQL Basics - A Quick Tour
NoSQL Basics - A Quick Tour
 
Simple Knowledge Organization System (SKOS) in the Context of Semantic Web De...
Simple Knowledge Organization System (SKOS) in the Context of Semantic Web De...Simple Knowledge Organization System (SKOS) in the Context of Semantic Web De...
Simple Knowledge Organization System (SKOS) in the Context of Semantic Web De...
 
Drupal camp atlanta 2013 mobile first
Drupal camp atlanta 2013 mobile firstDrupal camp atlanta 2013 mobile first
Drupal camp atlanta 2013 mobile first
 
Single Page Applications
Single Page ApplicationsSingle Page Applications
Single Page Applications
 
Web Summer Camp Keynote
Web Summer Camp KeynoteWeb Summer Camp Keynote
Web Summer Camp Keynote
 
Intro to-html-backbone-angular
Intro to-html-backbone-angularIntro to-html-backbone-angular
Intro to-html-backbone-angular
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
 
Exploiting Semantic Web Techniques For Representing And Utilising
Exploiting Semantic Web Techniques For Representing And UtilisingExploiting Semantic Web Techniques For Representing And Utilising
Exploiting Semantic Web Techniques For Representing And Utilising
 
Werfel, j. 2006: extended stigmergy in collective construction.in life intel...
Werfel, j. 2006: extended stigmergy in collective construction.in life  intel...Werfel, j. 2006: extended stigmergy in collective construction.in life  intel...
Werfel, j. 2006: extended stigmergy in collective construction.in life intel...
 
Seattle Data Geeks: Hadoop and Beyond
Seattle Data Geeks: Hadoop and BeyondSeattle Data Geeks: Hadoop and Beyond
Seattle Data Geeks: Hadoop and Beyond
 
Measurement and modeling of the web and related data sets
Measurement and modeling of the web and related data setsMeasurement and modeling of the web and related data sets
Measurement and modeling of the web and related data sets
 
Beyond the Page
Beyond the PageBeyond the Page
Beyond the Page
 
OMG Callimachus Demo 20120322 small
OMG Callimachus Demo 20120322 smallOMG Callimachus Demo 20120322 small
OMG Callimachus Demo 20120322 small
 
Big table presentation-final
Big table presentation-finalBig table presentation-final
Big table presentation-final
 
Social Network Analysis Introduction including Data Structure Graph overview.
Social Network Analysis Introduction including Data Structure Graph overview. Social Network Analysis Introduction including Data Structure Graph overview.
Social Network Analysis Introduction including Data Structure Graph overview.
 
Building Next-Gen Web Applications with the Spring 3 Web Stack
Building Next-Gen Web Applications with the Spring 3 Web StackBuilding Next-Gen Web Applications with the Spring 3 Web Stack
Building Next-Gen Web Applications with the Spring 3 Web Stack
 
CloudDesk - Cloud operating system
CloudDesk - Cloud operating systemCloudDesk - Cloud operating system
CloudDesk - Cloud operating system
 
Getting Started with Meteor
Getting Started with MeteorGetting Started with Meteor
Getting Started with Meteor
 
The NoSQL Movement
The NoSQL MovementThe NoSQL Movement
The NoSQL Movement
 

Mehr von Cory Foy

Defending Commoditization: Mapping Gameplays and Strategies to Stay Ahead in ...
Defending Commoditization: Mapping Gameplays and Strategies to Stay Ahead in ...Defending Commoditization: Mapping Gameplays and Strategies to Stay Ahead in ...
Defending Commoditization: Mapping Gameplays and Strategies to Stay Ahead in ...Cory Foy
 
When Code Cries
When Code CriesWhen Code Cries
When Code CriesCory Foy
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataCory Foy
 
Mud Tires: Getting Traction in Legacy Code
Mud Tires: Getting Traction in Legacy CodeMud Tires: Getting Traction in Legacy Code
Mud Tires: Getting Traction in Legacy CodeCory Foy
 
Fostering Software Craftsmanship
Fostering Software CraftsmanshipFostering Software Craftsmanship
Fostering Software CraftsmanshipCory Foy
 
Delivering What's Right
Delivering What's RightDelivering What's Right
Delivering What's RightCory Foy
 
Koans and Katas, Oh My! From Øredev 2010
Koans and Katas, Oh My! From Øredev 2010Koans and Katas, Oh My! From Øredev 2010
Koans and Katas, Oh My! From Øredev 2010Cory Foy
 
Technically Distributed - Tools and Techniques for Distributed Teams
Technically Distributed - Tools and Techniques for Distributed TeamsTechnically Distributed - Tools and Techniques for Distributed Teams
Technically Distributed - Tools and Techniques for Distributed TeamsCory Foy
 
Growing and Fostering Software Craftsmanship
Growing and Fostering Software CraftsmanshipGrowing and Fostering Software Craftsmanship
Growing and Fostering Software CraftsmanshipCory Foy
 
IronRuby for the .NET Developer
IronRuby for the .NET DeveloperIronRuby for the .NET Developer
IronRuby for the .NET DeveloperCory Foy
 
Blackberry 101 - Day of Mobile, March 2010
Blackberry 101 - Day of Mobile, March 2010Blackberry 101 - Day of Mobile, March 2010
Blackberry 101 - Day of Mobile, March 2010Cory Foy
 
Lean and Kanban Principles for Software Developers
Lean and Kanban Principles for Software DevelopersLean and Kanban Principles for Software Developers
Lean and Kanban Principles for Software DevelopersCory Foy
 
Tools for Agility
Tools for AgilityTools for Agility
Tools for AgilityCory Foy
 

Mehr von Cory Foy (13)

Defending Commoditization: Mapping Gameplays and Strategies to Stay Ahead in ...
Defending Commoditization: Mapping Gameplays and Strategies to Stay Ahead in ...Defending Commoditization: Mapping Gameplays and Strategies to Stay Ahead in ...
Defending Commoditization: Mapping Gameplays and Strategies to Stay Ahead in ...
 
When Code Cries
When Code CriesWhen Code Cries
When Code Cries
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and Data
 
Mud Tires: Getting Traction in Legacy Code
Mud Tires: Getting Traction in Legacy CodeMud Tires: Getting Traction in Legacy Code
Mud Tires: Getting Traction in Legacy Code
 
Fostering Software Craftsmanship
Fostering Software CraftsmanshipFostering Software Craftsmanship
Fostering Software Craftsmanship
 
Delivering What's Right
Delivering What's RightDelivering What's Right
Delivering What's Right
 
Koans and Katas, Oh My! From Øredev 2010
Koans and Katas, Oh My! From Øredev 2010Koans and Katas, Oh My! From Øredev 2010
Koans and Katas, Oh My! From Øredev 2010
 
Technically Distributed - Tools and Techniques for Distributed Teams
Technically Distributed - Tools and Techniques for Distributed TeamsTechnically Distributed - Tools and Techniques for Distributed Teams
Technically Distributed - Tools and Techniques for Distributed Teams
 
Growing and Fostering Software Craftsmanship
Growing and Fostering Software CraftsmanshipGrowing and Fostering Software Craftsmanship
Growing and Fostering Software Craftsmanship
 
IronRuby for the .NET Developer
IronRuby for the .NET DeveloperIronRuby for the .NET Developer
IronRuby for the .NET Developer
 
Blackberry 101 - Day of Mobile, March 2010
Blackberry 101 - Day of Mobile, March 2010Blackberry 101 - Day of Mobile, March 2010
Blackberry 101 - Day of Mobile, March 2010
 
Lean and Kanban Principles for Software Developers
Lean and Kanban Principles for Software DevelopersLean and Kanban Principles for Software Developers
Lean and Kanban Principles for Software Developers
 
Tools for Agility
Tools for AgilityTools for Agility
Tools for Agility
 

Kürzlich hochgeladen

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 

Kürzlich hochgeladen (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 

Patterns in Rails

  • 1. Patterns in Rails Cory Foy @cory_foy cory@8thlight.com www.8thlight.com Friday, June 21, 13
  • 4. “The specific patterns out of which a building or a town is made may be alive or dead. To the extent they are alive, they let our inner forces loose, and set us free; but when they are dead, they keep us locked in inner conflict.” Christopher Alexander - “The Timeless Way of Building” Friday, June 21, 13
  • 5. “And it turns out...behind all processes which allow us to make buildings live, there is a single common process. But though this method is precise, it cannot be used mechanically. Indeed it turns out, in the end, that what this method does is simply free us from all method.” Christopher Alexander - “The Timeless Way of Building” Friday, June 21, 13
  • 6. “...we have so far beset ourselves with rules, and concepts, and ideas of what must be done to make a building or a town alive, that we have become afraid of what will happen naturally, and convinced that we must work within a “system” and with “methods” since without them our surroundings will come tumbling down in chaos.” Christopher Alexander - “The Timeless Way of Building” Friday, June 21, 13
  • 7. Naming something the name of a pattern does not make it that pattern Friday, June 21, 13
  • 12. “From the beginning, the Rails framework turned web development on its head with the insight that the vast majority of time spent on projects amounted to meaningless sit-ups. Instead of having the time to think your domain-specific code, you’d spend the first few weeks of a project deciding meaningless details.” - Yahuda Katz, The Rails 3 Way Friday, June 21, 13
  • 13. “[Rails is] not a blank slate equally tolerant of every kind of expression. On the contrary, it trades that flexibility for the convenience of ‘what most people need most of the time to do most things’” - David Heinmeier Hansson - The Rails 3 Way Friday, June 21, 13
  • 14. Not to be confused with Ruby (programming language). - Wikipedia Friday, June 21, 13
  • 15. Ruby on Rails, often simply Rails, is an open source web application framework which runs on the Ruby programming language. It is a full-stack framework: it allows creating pages and applications that gather information from the web server, talk to or query the database, and render templates out of the box. As a result, Rails features a routing system that is independent of the web server. Friday, June 21, 13
  • 16. Ruby on Rails emphasizes the use of well- known software engineering patterns and principles, such as active record pattern, convention over configuration (CoC), don't repeat yourself (DRY), and model-view- controller (MVC). Friday, June 21, 13
  • 17. REST Routing Validations Controllers Action View Action Mailer Active Record Authentication Session Management Background Processing Caching and Performance Extending Rails with Plugins Friday, June 21, 13
  • 18. Model-View Controller Active Record Template View Front Controller Single Table Inheritance Friday, June 21, 13
  • 21. Name Model-View Controller Intent Separate the presentation of the model from the view, and separate the wiring of the model to the view Motivation A web application which has many models that need to be interacted with by end users Implementation View, Model and Controller should be in separate classes.View should depend on model, but not vice versa Consequences May be overkill for simple systems where the model has very little behavior Friday, June 21, 13
  • 23. Name Front Controller Intent Consolidate request handling by channeling requests through a single handler object Motivation Centralize the logic and handling for the many things that need to happen for a complex web site Implementation Create a class to handle all calls for a web site, and determines the correct classes to dispatch the request to Consequences More complicated than a Page Controller. Can turn into a God class Friday, June 21, 13
  • 25. Name Mapper Intent Set up communications between two subsystems that need to stay ignorant of each other Motivation Allow two independent systems to be able to talk to each other without them being dependent on each other or the mapper Implementation Initialize the mapper (maybe using a Front Controller) and configure the communication between systems Consequences May be difficult to initialize and configure the mapper since the subsystems can’t know about it Friday, June 21, 13
  • 27. Name Active Record Intent An object that wraps a row in a database table, encapsulates the access, and adds domain logic on that data Motivation Simplify the need to persist data by putting the data access logic in the domain object Implementation Each class is responsible for saving and loading to the database, and for any domain logic that acts on the data Consequences Best when domain logic isn’t too complex, and when model corresponds directly to the database table. Couples system to DB Friday, June 21, 13
  • 31. Name Single Table Inheritance Intent Represent an inheritance hierarchy of classes as a single table that has columns for all of the fields of the classes Motivation Minimize the number of joins when representing an inheritance structure in a relational database Implementation A single table contains all of the fields for the subclasses. Classes may or may not use all of the fields. Consequences Since not all columns are used, may be confusing. May cause large tables. Only have a single namespace for fields. Friday, June 21, 13
  • 33. Name TemplateView Intent Render information into HTML by embedding markers in an HTML page Motivation Allow HTML pages to be created as if they were static, but still be able to insert dynamic data Implementation Embed placeholders into a static HTML page when it’s written. Replace placeholders with content at runtime. Consequences Easy to put complicated logic in the view. Harder to test since generally designed to work within a web server Friday, June 21, 13
  • 35. Software is our craft TM 8th Light Cory Foy (@cory_foy) cory@8thlight.com www.8thlight.com Friday, June 21, 13