Android中的MVP笔记之五: MVP和MVVM的区别

谷歌关于mvvm的官方示例地址:

https://github.com/googlesamples/android-architecture/tree/dev-todo-mvvm-databinding/

 

MVP( Model-View-Presenter)和MVVM (Model-View-ViewModel) 的区别引用官方的话就是

The ViewModel in MVVM is very similar to the Presenter in MVP. The main difference has to do with the communication between View and ViewModel/Presenter:

  • MVVM: when the ViewModel is modified, the View is updated by a library or framework. There's no way to update the View directly from the ViewModel, as it doesn't have this reference.
  • MVP: The Presenter has a reference to the view so when a change is necessary, the presenter calls the view to explicitly make the change.

MVP 模式在安卓开发中可以不使用任何额外的支持库,也不需要其他的第三方类库,各层之间通过组合模式相互拥有所需要的实例,通过回调接口传递数据和处理逻辑,以达到让View层只专注于界面显示,P层负责在处理逻辑并作为View与Model的桥梁。

MVVM模式在安卓中的实现,需要使用官方提供的android.databinding库,当然android.databinding库也可以使用在MVP模式里,MVP模式可以结合android.databinding库使用,也可以不使用,但MVVP模式一定要使用android.databinding库。

根据官方的说明,MVP与MVVP的最大区别在于MVP模式里,P层以拥有View层的引用,当需要更新View时,P层通知View层更新界面,而MVVP模式里,ViewModel层不再拥有View的引用,View的更新和数据绑定通过android.databinding自动实现。

 

转载于:https://my.oschina.net/u/3038281/blog/863468

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值