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

相关文章
相关标签/搜索