幾個框架名稱MVC/MVP/MVVM
MVC:
Model, View, Control
MVP:
Model, View, Presenter
MVVM:
Model, View, ViewModel
在這之間,先前談的介面就是View,它包含了:Activity, fragment, View, Adapter 等等
在最新的架構,Google 提出了ViewModel(https://developer.android.com/topic/libraries/architecture/viewmodel),它是做為View/Model之間的交換、邏輯處理 (https://developer.android.com/jetpack/guide)
主要的目的跟MVP接近,但奐成了DataBinding 來作業
官方也提出了幾點重要的參考:
Avoid designating your app's entry points—such as activities, services, and broadcast receivers—as sources of data.
Create well-defined boundaries of responsibility between various modules of your app.
Expose as little as possible from each module.
Consider how to make each module testable in isolation.
Focus on the unique core of your app so it stands out from other apps.
Persist as much relevant and fresh data as possible.
Assign one data source to be the single source of truth.
MVVM 另外有幾個優點:資料趨動、下層元件不需瞭解上層元件(不必知道View是誰)、職責清楚
官方的介紹完整易讀,十分推薦