MVVM disappointment

Right now I’m at chapter 24 and I’m very disappointed that chapter 19 introduced DataBinding and MVVM and then nothing came out of it.

From my peeks into later chapters, MVVM and DataBinding aren’t used which is very disappointing. Maybe I’m wrong but I swear whenever I looked into code, it used old R.findViewById() and not Data Binding. What was the rationale behind that decision?

My personal thoughts on why from chapter 19 onwards, MVVM + DataBinding should’ve been used:

  • one chapter is simply not enough for such a broad concept
  • we already had some experience with classic MVC from previous chapters
  • reverting back to classic MVC makes us simply forget chapter 19 existed at all, making chapter 19 seem like nothing more than a passing example
  • as far as I know, MVVM + DataBinding (or Butterknife/View Binding) are used a lot. Since the book already uses commonly used tools like Retrofit or Room, why not use the most popular Android architecture?

Thoughts?

Hey there!

MVVM and Data Binding are definitely commonly used patterns in the Android community. When updating the book to the fourth edition we had a few reasons for restricting their usage to BeatBox.

One main reason is that the PhotoGallery series introduces some significant content and leaving these out provided focus for this new content.

Our other reasons mostly revolve around how quickly the platform is evolving. The official guide to app architecture (https://developer.android.com/jetpack/docs/guide) does not mention data binding in its implementation. ViewBinding (https://developer.android.com/topic/libraries/view-binding) is also being added as an alternative to DataBinding which has fewer features but has much better build performance. In the long term, Jetpack Compose (https://developer.android.com/jetpack/compose) is poising itself to remove the need for data binding all together. In the end, there are many ways to grab references to your views and I’m sure more will come out in the future.

Due to these reasons we aimed to introduce MVVM with data binding but decided not to push it further in Photo Gallery. In our own projects, we often feel that the combination of the Jetpack ViewModels with LiveData (or something like Kotlin Flow) to push data to the view can get you most of the benefit of a strict MVVM view model.

Brian

The latest update to Android Studio 3.6 now supports Jetpack View Binding