SlideShare a Scribd company logo
STOP! Use case time!
                              Or, a brief introduction to DCI.




Wednesday, January 9, 13
Who am I?
                       André Medeiros
                       Rubyist for 7+ years
                       @superdealloc
                       github.com/andremedeiros
                       quintel.com




Wednesday, January 9, 13
You’ve probably heard of it




Wednesday, January 9, 13
You’ve probably heard of it




Wednesday, January 9, 13
You’ve probably heard of it




Wednesday, January 9, 13
You’ve probably heard of it
                       “DCI in Ruby is completely broken”
                       - Tony Arcieri (@bascule)
                       “Rails Developers Should Take DCI Seriously”
                       - Giles Bowkett (@gilesgoatboy)




Wednesday, January 9, 13
Wednesday, January 9, 13
How I develop apps
                • UI first approach
                • UI directly maps to operations within the code
                • MVC doesn’t always conform to this standard of
                       development




Wednesday, January 9, 13
DCI is great for this approach
                       Invented by Trygve Reenskaug
                       Comes in where MVC fails: capturing behavior
                       Places interaction in obvious places
                       Models represent entities, not behavior
                       Splits what an object is from what it does




Wednesday, January 9, 13
D is for Data
                       What the object is
                       Persistence
                       Structure




Wednesday, January 9, 13
C is for Cookie Context
                       Class which enacts one or more use cases
                       Instantiated by a user action
                       Mixes in participating objects with Roles
                       Responsible for acting out the use case




Wednesday, January 9, 13
I is for Interaction
                       What the system does
                       Logic is contained in Role modules
                       Implemented by mixing in objects with Roles in a given
                       Context or use case




Wednesday, January 9, 13
How it works
                 Controller      starts use case   Context




Wednesday, January 9, 13
How it works
                 Controller      starts use case       Context

                               finds or creates the
                    Context    participating objects   Object(s)




Wednesday, January 9, 13
How it works
                 Controller             starts use case          Context


                    Context                                      Object(s)


        mixes in all the roles needed
                                                     Role
                                                       Role
                                                          Role


Wednesday, January 9, 13
How it works
                 Controller            starts use case          Context


                    Context                                     Object(s)


            invokes the role methods
                                                    Role
                                                      Role
                                                         Role


Wednesday, January 9, 13
Code Samples



Wednesday, January 9, 13
class TransfersController
                  def create
                    @source = Account.find(params[:source_id])
                    @destination = Account.find(params[:dest_id])

                    @source.balance -= amount
                    @destination.balance += amount
                  end
                end




Wednesday, January 9, 13
class MoneyTransfer
                  def initialize(source, destination)
                    @source = source
                    @destination = destination
                    assign_transferrer(@source)
                  end

                     def execute(amount)
                       @source.transfer_to(@destination, amount)
                     end

                     private
                       def assign_transferrer(account)
                         account.extend(Transferrer)
                       end

                           module Transferrer
                             def transfer_to(destination, amount)
                               self.balance -= amount
                               destination.balance += amount
                             end
                           end
                end

Wednesday, January 9, 13
Advantages
                       Keeps the model slim (fat != obese)
                       Business logic is easy to find and track down
                       Facilitates reusability
                       Highly testable




Wednesday, January 9, 13
FUD
                       Object#extend kills kittens




Wednesday, January 9, 13
FUD
                       Concerns do the exact same thing
                       It’s not real OO
                       Makes you write more code




Wednesday, January 9, 13
Questions?



Wednesday, January 9, 13

More Related Content

PDF
Data Context Interaction - What is it good for?
PDF
The State of Puppet
PDF
When Tdd Goes Awry
PDF
Lessons I Learned While Scaling to 5000 Puppet Agents
PDF
From a monolithic Ruby on Rails app to the JVM
PDF
Microservices and functional programming
KEY
Clean Code
PDF
NodeJS: Writing tests -- A Beginners' Guide
Data Context Interaction - What is it good for?
The State of Puppet
When Tdd Goes Awry
Lessons I Learned While Scaling to 5000 Puppet Agents
From a monolithic Ruby on Rails app to the JVM
Microservices and functional programming
Clean Code
NodeJS: Writing tests -- A Beginners' Guide

Similar to STOP! Use case time! (6)

PDF
D3 interactivity Linegraph basic example
PDF
40 Drupal modules you should be using in 2013
PDF
Intro to Laravel PHP Framework
PDF
Writing testable code
PDF
Solit 2013, Behaviour Driven Development, Ихелис Александр
PDF
Rails Intro & Tutorial
D3 interactivity Linegraph basic example
40 Drupal modules you should be using in 2013
Intro to Laravel PHP Framework
Writing testable code
Solit 2013, Behaviour Driven Development, Ихелис Александр
Rails Intro & Tutorial
Ad

Recently uploaded (20)

PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Getting Started with Data Integration: FME Form 101
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
A Presentation on Artificial Intelligence
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
1. Introduction to Computer Programming.pptx
PDF
project resource management chapter-09.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Approach and Philosophy of On baking technology
Accuracy of neural networks in brain wave diagnosis of schizophrenia
SOPHOS-XG Firewall Administrator PPT.pptx
Web App vs Mobile App What Should You Build First.pdf
1 - Historical Antecedents, Social Consideration.pdf
Getting Started with Data Integration: FME Form 101
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Chapter 5: Probability Theory and Statistics
Zenith AI: Advanced Artificial Intelligence
Hindi spoken digit analysis for native and non-native speakers
A Presentation on Artificial Intelligence
WOOl fibre morphology and structure.pdf for textiles
Univ-Connecticut-ChatGPT-Presentaion.pdf
Programs and apps: productivity, graphics, security and other tools
Building Integrated photovoltaic BIPV_UPV.pdf
1. Introduction to Computer Programming.pptx
project resource management chapter-09.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Encapsulation_ Review paper, used for researhc scholars
Approach and Philosophy of On baking technology
Ad

STOP! Use case time!

  • 1. STOP! Use case time! Or, a brief introduction to DCI. Wednesday, January 9, 13
  • 2. Who am I? André Medeiros Rubyist for 7+ years @superdealloc github.com/andremedeiros quintel.com Wednesday, January 9, 13
  • 3. You’ve probably heard of it Wednesday, January 9, 13
  • 4. You’ve probably heard of it Wednesday, January 9, 13
  • 5. You’ve probably heard of it Wednesday, January 9, 13
  • 6. You’ve probably heard of it “DCI in Ruby is completely broken” - Tony Arcieri (@bascule) “Rails Developers Should Take DCI Seriously” - Giles Bowkett (@gilesgoatboy) Wednesday, January 9, 13
  • 8. How I develop apps • UI first approach • UI directly maps to operations within the code • MVC doesn’t always conform to this standard of development Wednesday, January 9, 13
  • 9. DCI is great for this approach Invented by Trygve Reenskaug Comes in where MVC fails: capturing behavior Places interaction in obvious places Models represent entities, not behavior Splits what an object is from what it does Wednesday, January 9, 13
  • 10. D is for Data What the object is Persistence Structure Wednesday, January 9, 13
  • 11. C is for Cookie Context Class which enacts one or more use cases Instantiated by a user action Mixes in participating objects with Roles Responsible for acting out the use case Wednesday, January 9, 13
  • 12. I is for Interaction What the system does Logic is contained in Role modules Implemented by mixing in objects with Roles in a given Context or use case Wednesday, January 9, 13
  • 13. How it works Controller starts use case Context Wednesday, January 9, 13
  • 14. How it works Controller starts use case Context finds or creates the Context participating objects Object(s) Wednesday, January 9, 13
  • 15. How it works Controller starts use case Context Context Object(s) mixes in all the roles needed Role Role Role Wednesday, January 9, 13
  • 16. How it works Controller starts use case Context Context Object(s) invokes the role methods Role Role Role Wednesday, January 9, 13
  • 18. class TransfersController def create @source = Account.find(params[:source_id]) @destination = Account.find(params[:dest_id]) @source.balance -= amount @destination.balance += amount end end Wednesday, January 9, 13
  • 19. class MoneyTransfer def initialize(source, destination) @source = source @destination = destination assign_transferrer(@source) end def execute(amount) @source.transfer_to(@destination, amount) end private def assign_transferrer(account) account.extend(Transferrer) end module Transferrer def transfer_to(destination, amount) self.balance -= amount destination.balance += amount end end end Wednesday, January 9, 13
  • 20. Advantages Keeps the model slim (fat != obese) Business logic is easy to find and track down Facilitates reusability Highly testable Wednesday, January 9, 13
  • 21. FUD Object#extend kills kittens Wednesday, January 9, 13
  • 22. FUD Concerns do the exact same thing It’s not real OO Makes you write more code Wednesday, January 9, 13