By Jeasmine Nahui

DevSnack #61: When building a new application, developers must consider which architecture to use. This decision will affect tests capabilities, modularity, extensibility and a bunch of other characteristics. In the past, there were not that many options for developers to choose from. There was a time that the only options were MVC or MVP. But now, with the introduction of Data Binding on the Google I/O 2015, a new approach for Android became available, the MVVM architecture. Let’s see how can we use this on Android

#1 – Data Binding

The main reason for using Data Binding will be to avoid boilerplate code that doesn’t require any brainpower. Yigit Boyar (@yigitboyar) and George Mount (@georgemount1) explain how to use Data Binding on Android projects. They also describe the way the code gets reduced, by setting the events handlers, data, and view logic on the layout, instead of the fragment or activity view.

#2 – MVVM Approach

In his post, Joe Birch (@hitherejoe) explains what MVVM is and all of its components. For making it easier for everyone, he shared an working example on Github where he uses Data Binding, so then we can learn how to use it with MVVM and why it makes MVVM possible.

#3 – Using MVVM on a project

In this link, Ross Hambrick (@rosshambrick) describes how to set up a project with Binding and ViewModel declarations, and bringing it all together. So, what are their limitations, and what is it still missing? Regarding the missing points, two-way binding functionality is currently available by including @={} instead of @{}.

#4 – From MVP to MVVM

Frode Nilsen outlines the main differences between MVP and MVVM. He also explains the reasons why it is not necessary to use certain frameworks like ButterKnife. Your code will be testable as long as you mock the Fragment using Robolectric and Mockito. It will not leak memory unless you start referencing ViewModels where you should not. Finally, you should not be using things that contain the line import android.content. If you are, you’re not supposed to.

#5 – MVVM For testing

Frank explains why this approach is perfect for testing. Because view model does not know which activity or fragment to use, it does not rely on them, so that we can test only the logic that matters.


Creative Commons License
DevSnack by Moove-it is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.