MVC considered harmful?!
DCI, Objects on Rails, Use-cases...
Code or it didn't happen...
the traditional way
Rails made me do it
Jamis Buck, 2006
there's more than Model, View & Controller
MVC makes use-cases difficult to read
use-case spread over many files
lack of cohesion
class has exactly one reason to change
Robert C. Martin, Agile Software Development, Principles, Patterns, and Practices
AR::Base already has a responsibility
Classes dictate methods of objects
A new hope
...which may lead to obesity (in traditional way)
Dumb data, application-independent business rules
Application-specific business rules == use-cases
Should be an implementation detail == a plugin
Should be an implementation detail == a plugin
Post.find(id)
vs.
current_user.blog.posts.find(id)
A new hope
examples
after
rake test?lib/tasks/tests.rakeautotest?~/.autotest
use-cases easy to follow
easier to modify
crazy fast tests
$ time rake test:units # Running tests: .................................................................................................................................................................. Finished tests in 33.363820s, 4.8855 tests/s, 8.5422 assertions/s. 163 tests, 285 assertions, 0 failures, 0 errors real 0m51.735s user 0m43.616s sys 0m2.795s
$ time rake test:units # Running tests: .................................................................................................................................................................. Finished tests in 33.363820s, 4.8855 tests/s, 8.5422 assertions/s. 163 tests, 285 assertions, 0 failures, 0 errors real 0m51.735s user 0m43.616s sys 0m2.795s
$ time rake test:usecases
# Running tests:
................................................
Finished tests in 0.081814s, 586.6967 tests/s, 1821.2042 assertions/s.
48 tests, 149 assertions, 0 failures, 0 errors, 0 skips
real 0m6.375s
user 0m5.115s
sys 0m1.175s
$ time rake test:usecases
# Running tests:
................................................
Finished tests in 0.081814s, 586.6967 tests/s, 1821.2042 assertions/s.
48 tests, 149 assertions, 0 failures, 0 errors, 0 skips
real 0m6.375s
user 0m5.115s
sys 0m1.175s
no Rails goodies
tedious requires
Thank you!
/