January 8, 2020

 

Android: one ViewModel per view

It's a surprisingly common belief of using one ViewModel class in several views (screens) in modern Android Jetpack-based MVVM architecture style. In reality ViewModel cannot be shared. There're lots of arguments against reusing ViewModel. Most obvious one is that it mixes data processing logics of different screens which increases complexity of implementing and testing of ViewModels.

Do not create huge ViewModels, keep it simple. Yes, it's more classes per view, however your support and development costs are closer to linear in time.

Labels: , , , , ,

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?