MVVM with Data Binding on Android
Now that Google has -finally- started working on a Data Binding engine, it’s time for me to start changing the way I use the Presentation Model pattern. Why use Presentation Model? It’s been talked a lot about this pattern, so I’m not going to re-explain the wheel. You can find useful references here, here, here and here. Very briefly, the main motivations to use this pattern are: Moves the presentation logic into specific components. This is specially important on Android, where views (Activities and Fragments, in our case) can get quite large. Improves testability and reusability, as controllers (Presenters or ViewModels) can be written in pure Java. Decouples the model from the view, so our business logic is completely independent. Why Model View ViewModel? I have been using MVP (and therefore Presenters) for about a year. It’s been great, as my code became more testable, and my activities/fragments got smaller. You can have a look at this gist by Christian Panadero to get an idea about how I and others use the Presentation Model with Passive View. But I still find that there is one more step forward: the MVVM pattern. ...