STOP! Use case time!                              Or, a brief introduction to DCI.Wednesday, January 9, 13
Who am I?                       André Medeiros                       Rubyist for 7+ years                       @superdeal...
You’ve probably heard of itWednesday, January 9, 13
You’ve probably heard of itWednesday, January 9, 13
You’ve probably heard of itWednesday, January 9, 13
You’ve probably heard of it                       “DCI in Ruby is completely broken”                       - Tony Arcieri ...
Wednesday, January 9, 13
How I develop apps                • UI first approach                • UI directly maps to operations within the code      ...
DCI is great for this approach                       Invented by Trygve Reenskaug                       Comes in where MVC...
D is for Data                       What the object is                       Persistence                       StructureWe...
C is for Cookie Context                       Class which enacts one or more use cases                       Instantiated ...
I is for Interaction                       What the system does                       Logic is contained in Role modules  ...
How it works                 Controller      starts use case   ContextWednesday, January 9, 13
How it works                 Controller      starts use case       Context                               finds or creates t...
How it works                 Controller             starts use case          Context                    Context           ...
How it works                 Controller            starts use case          Context                    Context            ...
Code SamplesWednesday, January 9, 13
class TransfersController                  def create                    @source = Account.find(params[:source_id])       ...
class MoneyTransfer                  def initialize(source, destination)                    @source = source              ...
Advantages                       Keeps the model slim (fat != obese)                       Business logic is easy to find a...
FUD                       Object#extend kills kittensWednesday, January 9, 13
FUD                       Concerns do the exact same thing                       It’s not real OO                       Ma...
Questions?Wednesday, January 9, 13
Upcoming SlideShare
Loading in...5
×

STOP! Use case time!

345
-1

Published on

A brief introduction to DCI

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
345
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

STOP! Use case time!

  1. 1. STOP! Use case time! Or, a brief introduction to DCI.Wednesday, January 9, 13
  2. 2. Who am I? André Medeiros Rubyist for 7+ years @superdealloc github.com/andremedeiros quintel.comWednesday, January 9, 13
  3. 3. You’ve probably heard of itWednesday, January 9, 13
  4. 4. You’ve probably heard of itWednesday, January 9, 13
  5. 5. You’ve probably heard of itWednesday, January 9, 13
  6. 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
  7. 7. Wednesday, January 9, 13
  8. 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 developmentWednesday, January 9, 13
  9. 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 doesWednesday, January 9, 13
  10. 10. D is for Data What the object is Persistence StructureWednesday, January 9, 13
  11. 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 caseWednesday, January 9, 13
  12. 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 caseWednesday, January 9, 13
  13. 13. How it works Controller starts use case ContextWednesday, January 9, 13
  14. 14. How it works Controller starts use case Context finds or creates the Context participating objects Object(s)Wednesday, January 9, 13
  15. 15. How it works Controller starts use case Context Context Object(s) mixes in all the roles needed Role Role RoleWednesday, January 9, 13
  16. 16. How it works Controller starts use case Context Context Object(s) invokes the role methods Role Role RoleWednesday, January 9, 13
  17. 17. Code SamplesWednesday, January 9, 13
  18. 18. class TransfersController def create @source = Account.find(params[:source_id]) @destination = Account.find(params[:dest_id]) @source.balance -= amount @destination.balance += amount end endWednesday, January 9, 13
  19. 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 endWednesday, January 9, 13
  20. 20. Advantages Keeps the model slim (fat != obese) Business logic is easy to find and track down Facilitates reusability Highly testableWednesday, January 9, 13
  21. 21. FUD Object#extend kills kittensWednesday, January 9, 13
  22. 22. FUD Concerns do the exact same thing It’s not real OO Makes you write more codeWednesday, January 9, 13
  23. 23. Questions?Wednesday, January 9, 13
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×