|
|
|
|
|
by metaphorm
4772 days ago
|
|
I'm not sure I understand the point of this. Am I just dense? Can someone explain in some detail? To me this looks like a superfluous layer of indirection that causes you to have to manage your object method calls through an "interactor" instead of the object itself. That's just breaking the encapsulation pattern of OOP and I imagine this is nightmarish in terms of its impact on reusability of your code. did I get it wrong or is this actually just a huge anti-pattern? |
|
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.)