0

I'm stack on applying MVP pattern to my project. I have 2 different activities: one obtains data from local database and the other makes mathematical calculations. In MVP pattern it is possible to use interactors and I'd like to use them in my project(not sure if I really need them in such a project but it is for the educational purpose; btw, do I need them?). Also, I have understood that they are used to connect to DBs, and some other jobs not directly related to design elements. So, if I would do my calculation and data retrieving in one interactor then I would declare this class 2 times and use its functionality for 50% each time but I think that is a bad practice. Hence, the thing that would work is just making 2 different interactors: one for data retrieving and one for math calculations. Is this okay? Because since these classes define main business rules of the project then I should have one interactor but I think that is not a very great solution.

S.Drumble1
  • 83
  • 1
  • 10

2 Answers2

0

Interactor is an object from VIPER architecture.

You can user Repository pattern. Just create 2 repositories, for example: MathCalculationsRepository and DataRetrievingRepository. But better will be if you decomposing data loading operation for a few repositories, for example: if you have requests that retrieve events and user data you can create UserRepository and EventsRepository.

Ivan Smetanin
  • 1,999
  • 2
  • 21
  • 28
0

Interactor (UseCase from original clean architecture) is a class, which contains all business-logic. Yes, create a single interactor and use them 50/50 is a bad idea, and yes - create 2 different interactors for different goals is a good idea (Because you separate logic by classes, and can reuse this classes).

But you are mistaken in that interactor used to connect with DB and network, for network and DB connections used Repository (also known as Gateway), which is used by interactor.

Mamykin Andrey
  • 1,352
  • 10
  • 13