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 library

  • model:事物逻辑以及数据结构等(如从网络获取数据、bean类等)
  • view:xml
  • viewModel:view与model之间的中间件

参考

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

猜你喜欢

转载自my.oschina.net/u/552375/blog/694035