Norway


Hello community,

I’ve given a task at my company to modularise some core functionality on project into separate library for common use.

Right now we have mvvm-base. For , we have Bean that extends BaseObservable. (Apparently the naming derives from Spring? I don’t know).

We’re also have ViewModel that holds the Bean. (Now the Bean is put into generics, like class ViewModel<B extends Bean>). ViewModel has responsibility to hold Bean and also process logic like HTTP Request, updating Bean, etc.

And then we’re also have Presenter class that have responsibility to handle view events. Says when a button is clicked, a method in Presenter is being called, inside that method, we call few method on View. That method in the View is executing some method to process logic on ViewModel.

DataBinding library is being used to bind ViewModel and Presenter to layout file.

So our view (assuming there is button to press and data to show) will have at least one instance of ViewModel and one instance of Presenter. Also the UI flow become like this:

View (onLoad, instantiate ViewModel, bind ViewModel to layout) -> ViewModel (logic, if any, update Bean)

View (onClick event is bind to method on Presenter) -> Presenter (call View method) -> View (receive message from presenter, execute logic from ViewModel) -> ViewModel (logic)

I know it’s kind of cluttered and the function of Presenter is kind of useless and responsibility of ViewModel is ambiguous. For now I have an idea to pack the whole ViewModel and Presenter into one class but I’m afraid I don’t have strong base as opinion to my . I’d like to know your opinion about it.

Also as a bonus: In my team, they’ve been using HttpURLConnection and AsyncTask to make network request, my senior told me to research alternative and he is mentions Volley and OkHttp. In my opinion, OkHttp is far better because it’s actively maintained. What do you think?

Thanks!



Source link

LEAVE A REPLY

Please enter your comment!
Please enter your name here