The Command Pattern: A Lightweight Alternative to DCI
February 09, 2012 - 11 Comments - ruby rails patterns command pattern dci
Recently the Rails community has seen a flurry of activity regarding a new approach to encapsulating business logic in Rails called Data, Context, Interaction, or, DCI. And rightfully so! The old mantra of “fat models, skinny controllers” has cracked with wisdom as models in larger and more complicated applications have become not just fat but in fact rather obese. Furthermore, the question of which model some piece of business logic should live in has always been vague regarding operations involving multiple models of different kinds.
It is a problem. The results have been sub-optimal design, testability, and readability, coupled with huge model files bloating into thousands of lines of code. The DCI approach has been explored at length as a possible solution. Mike Pack wrote a great article both explaining the benefits of DCI and an example implementation.
The DCI Pattern: Pros and Cons
There are some clear benefits of the DCI approach, especially compared to the old way of just shoving business logic into the nearest relevant model:
- *Sk…
