View ViewModel Service Layer ViewModel Android Architectural Component Coroutines Android Architectural Component ViewModel Helper (Activity, Fragment) Service 1 Service 2 Service 3 Service N Repository Data Model Dummy activity/fragment A loosely coupled view Lightweight, clean code and easy to manage ViewModels SRP 1) Fetch, Store then Update. 2) Update from cache, Ftech, Store then Update. Caching Manager
plate code on view layer by using Data Binding Lib. • Easy to test UI (higher testing coverage) • Activity is not needed to test UI <TextView android:id="@+id/featureSettingTitle" ……… android:text="@{viewmodel.title}" ………… app:layout_constraintTop_toTopOf="parent" /> class ServiceView(override rootView: ViewGroup) : BaseView(rootView), OverviewAdapter.OverviewListener, ServiceContract.View { ………. /** * Hiding Shimmer View */ override fun hideShimmer() { super.hideShimmer() rootView.shimmerView.visibility = View.GONE
ViewModel First Approach • Less responsibilities à à à is request permission View’s responsibility??? • Very simple and lightweight, View shouldn’t be complex. • Easy to test (Also, Testing UI is independent from System)
(Single Responsibility Principle) to main components. • Loosely coupled components/logic • Again, Easy to test logic à Higher testing coverage à better quality. • Easy to maintain and support.