Reputation: 2677
I'm trying to implenet clean architecture in my app.
I have LoadItemsInteractor
that loads all items from repository and also I have LoadItemsByIdInteractor
that loads items by id.
I have a method, that filters received items, and both interactors share it. I wonder where should I place this code. Options:
Utils
class with static method filter
, both interactors call it before returning values to presenterBaseLoadItemsInteractor
that implements filter
method and inherit both interactors from it.FilterItemsInteractor
and pass the result of LoadItemsInteractor
and LoadItemsByIdInteractor
execution (from presenter or inside concrete interactor).What is the cleanest way of implementing this?
Upvotes: 1
Views: 1029
Reputation: 3573
The plain loading of something from some data store belongs into the circle of interface adapters and is usually called repository. All logic u apply to the loaded data belongs to an Interactor. And as already stated an Interactor can have multiple methods if this does not violate SRP.
Upvotes: 0
Reputation: 353
You can unify both interactor in one, and through the filter send the id and the rest of objects you want to filter to send it to the repository, thus saving you repeated code. At the end loadItems is the use case and byId is a filter, it adds the id to the filter and unifies the interactor into one.
Upvotes: 1