I'm currently building an android application and wanted to base it on "clean architecture" similarly as suggested by the following authors:
View (Fragment) <-> Presenter <-> Interactor <-> Repository
In the current design there is 1 interactor per display (a display may include multiple fragments e.g. ViewPager with 30 fragments of the same type) and 1 presenter per fragment. Presenter and Interactor have no framework dependencies to allow easy testing.
My main concern is the implementation of the Interactors/UseCases and their relation to Presenters (MVP) or ViewModel (MVVM).
It is planned to have the Interactor first fetch all required business objects (BO) for a display. The fetching is done synchronously from the data layer and each received BO directed to the Presenter. This causes a delay until all data is shown in the view.
Further it registers for updates for BOs it is interested in (the same as fetched before) to continuously update the view through the Presenters.
I'm thus looking for a guideline of how to set up an Interactor in my case. The implementations mentioned above have one task, work it off then are done and the Interactor background thread may be closed.
In my case the Interactor registers for updates from the datalayer and waits to handle them, then posts the data to the Presenter UI thread, thus lives as long as there is a presenter listening.
This functionality is different and I'm looking for a good practice to make it work with a "clean architecture".
Interactors: little, reusable chunks of code that abstract logic from presenters while simplifying your app and making future changes effortless. But are they all they're cracked up to be? Before I go on, the interactor pattern has a number of variations in Android.
Interactor is a class which separates Domain Layer from Presentation Layer. In simple words it provides way to write business logic separately than code which is used for manipulate UI (by binding data to UI/ animate / navigation). So Interactor is mediator between Presenter/ViewModel and Repository pattern.
MVP (Model — View — Presenter) architecture is one of the most popular architecture patterns and is valid in organizing the project. MVP (Model — View — Presenter) comes into the picture as an alternative to the traditional MVC (Model — View — Controller) architecture pattern.
If your project is large and sophisticated, with a lot of business logic, for example, Clean architecture has many advantages. However, for smaller and simpler tasks, the benefits may not be worth it — you'll end up writing more code and increasing complexity with all the layers, as well as investing more time.
So if I understand your question, your concern or doubts comes because your Interactor is not going to execute a task and then finish, but is going to be subscribed or listening until an operation is done.
In my opinion that's perfectly fine, an Interactor implements a use case, and in your program that async request is a use case, it doesn't matter if it takes time and is an asynchronous task or is a synchronous operation.
It is still a use case where the Presenter will instantiate the Interactor and when this has finished, it will send back the result of the operation. As long as you keep the modularity and the Presenter and Interactor are not coupled with direct dependencies but they communicate via indirection, that's perfectly fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With