Reputation: 141
I've been doing a lot of research and trying to use MVP with Clean Architecture in my app, but still i have a lot of confusion and don't understand it completely. My biggest doubt is: where should non database related, like complex ma mathematical calculations, logic go? Every example app on the internet i found has to simply save and retrieve some data from the database.
For instance i have a screen where user need to insert 4 values and then i have code that takes this values, perform some calculations and return object that represents data to be displayed.
My question now is: where should i position the class or code responsible for producing the result in an MVP with clean architecture project, with following structure:
view <--> presenter <--> use cases <--> repositories
View sends input to the presenter, but then ? Also many examples use different "services" classes and in some of them they are connected to presenter and in other to repository.
Upvotes: 2
Views: 793
Reputation: 227
You should write your complex and logical code in presenter itself why?-> if you ever need any database values so you can get it from presenter by running thread and do further calculations.
if is there any validations you should use common classes to get the result
for ex.
view needs some result on inputs you can pass it to presenter , presenter will process the inputs and return the data back to view.
follow this link it will help you to understand MVP like a pro
Upvotes: 0
Reputation: 18002
Use cases are part of the model. In the model there are the data (the pojos to define how the data is stored in memory) and the use cases. All your business logic as this complex mathematical calculations must be in one or many use cases.
The view will get the data and pass it to the presenter which should create a thread (in one of the many ways to run code asynchronously, I like using threadpoolexecutors for this) to run the use case which will do the maths and answer the presenter. And finally, the presenter will send the data back to the view.
Unless you have to retrieve any data (from sensors, files, databases, url responses...) or permanently store it I don't think you need a repository in this case.
Upvotes: 2