STOP! Use case time!
Upcoming SlideShare
Loading in...5
×
 

STOP! Use case time!

on

  • 403 views

A brief introduction to DCI

A brief introduction to DCI

Statistics

Views

Total Views
403
Views on SlideShare
403
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

STOP! Use case time! STOP! Use case time! Presentation Transcript

  • 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.comWednesday, 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 itWednesday, 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 developmentWednesday, 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 doesWednesday, January 9, 13
  • D is for Data What the object is Persistence StructureWednesday, 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 caseWednesday, 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 caseWednesday, January 9, 13
  • How it works Controller starts use case ContextWednesday, 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 RoleWednesday, January 9, 13
  • How it works Controller starts use case Context Context Object(s) invokes the role methods Role Role RoleWednesday, January 9, 13
  • Code SamplesWednesday, 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 endWednesday, 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 endWednesday, January 9, 13
  • Advantages Keeps the model slim (fat != obese) Business logic is easy to find and track down Facilitates reusability Highly testableWednesday, January 9, 13
  • FUD Object#extend kills kittensWednesday, January 9, 13
  • FUD Concerns do the exact same thing It’s not real OO Makes you write more codeWednesday, January 9, 13
  • Questions?Wednesday, January 9, 13