SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Ähnlich wie STOP! Use case time!

D3 interactivity Linegraph basic example
D3 interactivity Linegraph basic exampleD3 interactivity Linegraph basic example
D3 interactivity Linegraph basic exampleAdam Pah
 
40 Drupal modules you should be using in 2013
40 Drupal modules you should be using in 201340 Drupal modules you should be using in 2013
40 Drupal modules you should be using in 2013Mariano
 
Intro to Laravel PHP Framework
Intro to Laravel PHP FrameworkIntro to Laravel PHP Framework
Intro to Laravel PHP FrameworkBill Condo
 
Writing testable code
Writing testable codeWriting testable code
Writing testable codeAlvaro Videla
 
Solit 2013, Behaviour Driven Development, Ихелис Александр
Solit 2013, Behaviour Driven Development, Ихелис АлександрSolit 2013, Behaviour Driven Development, Ихелис Александр
Solit 2013, Behaviour Driven Development, Ихелис Александрsolit
 

Ähnlich wie STOP! Use case time! (6)

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

Kürzlich hochgeladen

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 

Kürzlich hochgeladen (20)

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 

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