Thursday, February 28, 2013

A decent article on what tends to upset me about rails


 I put some of the blame on Rails itself, which has guided developers to use Controllers, Models, or Libraries, and nothing else. 
 Are your tests slow (>1s to run a single unit test)? Do your tests have large ungainly setup? Are you using factory_girl in your unit tests? Are you mocking implementation instead of interfaces? 

I'm only really into my 3rd or 4th rails application of appreciable size, and they all seem to have this kind of problem - the tight coupling of active record to the model, and the model mixing persistence with business logic is rampart.

Enter the Interactor. An Interactor handles a use case. It pulls together the models and libraries it needs to process a single business rule, and then it’s done. These objects are very easy to test and use and in proper OO fashion can be used anywhere the app needs to apply the use case or business rule.
I dont think you need to call it an Interactor, it's just a Model. Not the relational-persistance kind, but the Model of your business logic - expressly applying SRP.

Enhanced by Zemanta

No comments: