O
O
orbit0702019-07-02 12:06:45
Android
orbit070, 2019-07-02 12:06:45

What is the best way to handle query results?

Hello.
I am studying android, the following question arose: how to properly process the results of queries and transfer them from the repository to the ViewModel or Presenter. So far, I have come across such approaches:
1. A callback interface is declared, ViewModel or Presenter implement this interface, and they are passed to the repository as a callback (since they implement it).
2. A callback interface is declared, but the ViewModel or Presenter does not implement it, and an instance of an anonymous class that implements the callback interface is passed to the repository as a callback.
3. In MVVM, I saw an example with Retrofit, where no callbacks from the ViewModel were transferred, but simply after the request has completed and the Retrofit callback has worked (onResponse or onFailure) inside the repository, LiveData is immediately returned from the repository to the ViewModel.
PS If I call something that is not callback, please let me know) The
question is, which of these approaches is more correct? Are there any reasons why you should abandon one of them? Can eat other approaches, more correct? I would be grateful for any information.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question