android-mvp-architecture
android-mvp-architecture copied to clipboard
Handle network response in datamanager
DataManager does not need to implement ApiHelper. This removes unnecessary implementation of getApiHeader. Helper methods to perform login can be extracted to a separate interface(LoginHelper) and implemented by datamanager. Datamanager will delegate the login tasks to Apihelper.
Presenter only needs to know if login was successful or some error occurred. So I've just returned an emtpy observable in case of successful response.
@ISatya Thank you. We highly appreciate your insights.
I have few concern in this approach.
- The DataManager code will become huge and unmanageable when the entire application start to take shape.
- If the presenter have to delegate the data from network to the view then there will be unnecessary interception by the DataManager. DataManager will do nothing with that data but to extract and then forward it to the presenter.
- In the above implementation the DataManager is handling the business logic of whether to logout user or log in. The business logic should be only handled by the presenter. DataManager should only be responsible for handling the data as told by the presenter.
Thanks
-
If the entire application data is handled by a single DataManager then it will get bloated. DataManager should be split into multiple managers. In current implementation, all tasks are implemented in a Single DataManager. If we extract login related tasks to a separate manager - LoginDataManager and do the same with any new modules that are added, individual data managers will be small and manageable.
-
Agreed. But in this case, presenter is responsible for handling network response. This adds additional responsibility of forwarding response to DataManager. If my understanding is correct, DataManager should be responsible of managing data. It should decide what to do with the response, whether to persist it or just pass it to the presenter or to convert it to a form required by the presenter. Presenter should not be forwarding network response. It should receive data from DataManager and use it to decide what the view should show.
-
Presenter is the one initiating logout or login. Presenter tells DataManager to perform logout call and DataManager does the required network calls, updating user session locally and then inform presenter whether logout was successful or not.
Thanks
@ISatya Agreed with most of your points. We will think on this and discuss.