by RKlophaus · 13y ago · 0 comments
When this happens, you can either have model objects that know too much about their surrounding environment, or you can put the code somewhere else.
In Rails, that "somewhere else" is usually a controller. But that's messy because now your application's logic is spread between a controller and multiple model objects.
Interactors are a way to clean that up. It allows you to put all of the code to accomplish a use case into one well-named place.
Good programming is about managing complexity. In practice, interactors have served us very well in managing complexity.
(Note: I work on the same code-base as the author of the article.)
e.g. CommentMixin would be an abstract controller class that is included in any controller that has an object that can be commented on.
Also, as the article describes, interactors are plain old ruby objects, so are straightforward to test. An Abstract Controller, being a Rails construct, would require you to jump through some Rails hoops to test.