mol
mol

Reputation: 2677

The cleanest way of filtering Interactors result

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:

What is the cleanest way of implementing this?

Upvotes: 1

Views: 1029

Answers (2)

plainionist
plainionist

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

Daniel RL
Daniel RL

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

Related Questions