MVC vs MVP vs MVVM

MVC

  • model:事物邏輯以及數據結構等(如從網絡獲取數據、bean類等)
  • view:視圖如何被展現,在android中通常爲xml佈局文件
  • controller:控制model中的數據如何在view中展現,表如今android中爲activity

MVP

  • model:事物邏輯以及數據結構等(如從網絡獲取數據、bean類等)
  • view:經過抽象出的接口來表示,在接口中定義一下跟界面操做相關的一些方法,如顯示消息、更新列表數據、隱藏某些控件等(這裏只涉及到界面的更新而不會關心數據是如何獲取的,也就是說數據會以參數的形式傳進來)。通常會經過讓activity實現這個接口,因此也能夠把activity做爲view來看待。activity做爲view的另一個重要的功能就是要處理用戶的交互事件,如點擊操做等
  • presenter:會持有一個view對象,經過model獲取相應的數據,而後經過調用view的方法進行界面的更新。

MVVM

Model-View-ViewModel is an architecural approach used to abstract the state and behaviour of a view, which allows us to separate the development of the UI from the business logic. This is accomplished by the introduction of a ViewModel, whos responsibility is to expose the data objects of a model and handle any of the applications logic involved in the display of a view.
mvvm的實現主要依賴於Data Binding libraryandroid

  • model:事物邏輯以及數據結構等(如從網絡獲取數據、bean類等)
  • view:xml
  • viewModel:view與model之間的中間件

參考

MVVM on Android: What You Need to Know
Approaching Android with MVVM
mvp examplegit

相關文章
相關標籤/搜索