理解android-architecture mvp

https://github.com/googlesamples/android-architecture

todo_mvp
在这里插入图片描述

A contract class which defines the connection between the view and the presenter.
An Activity which creates fragments and presenters.
A Fragment which implements the view interface.
A presenter which implements the presenter interface in the corresponding contract.

Presentation Layer

契约类Contract View和Presenter的联系
Activity中实例化Fragment和Presenter
创建Fragment中实现BaseView接口
创建Presenter并实现契约类中的Presenter接口

Data Layer

data :该分包下主要是数据层的代码,即 MVP 中的 Model 层

接口TasksDataSource 规范操作数据的接口
类TasksRemoteDataSource 实现TasksDataSource 接口,实现真正操作数据的逻辑。
类TasksLocalDataSource 实现TasksDataSource 接口,实现真正操作数据的逻辑。
类TasksRepository 实现TasksDataSource接口,持有TasksRemoteDataSource mTasksLocalDataSource 对象。

在这里插入图片描述

todo-mvp-clean

在这里插入图片描述

It’s based on the MVP sample, adding a domain layer between the presentation layer and repositories, splitting the app in three layers:

MVP: Model View Presenter pattern from the base sample.
Domain: Holds all business logic. The domain layer starts with classes named use cases or interactors used by the application presenters. These use cases represent all the possible actions a developer can perform from the presentation layer.
Repository: Repository pattern from the base sample

增加了域层use cases 表示presentation layer的行为

Key concepts
The big difference with base MVP sample is the use of the Domain layer and use cases. Moving the domain layer from the presenters will help to avoid code repetition on presenters (e.g. Task filters).
Use cases define the operations that the app needs. This increases readability since the names of the classes make the purpose obvious (see tasks/domain/usecase/).
Use cases are good for operation reuse over our domain code. CompleteTask is a good example of this as it’s used from both the TaskDetailPresenter and the TasksPresenter.
The execution of these use cases is done in a background thread using the command pattern. The domain layer is completely decoupled from the Android SDK or other third party libraries.

将domain layer从 presenter分离,有利于减少 presenter的代码重复
Use cases提高代码的可读性
Use cases利用command模式,后台线程执行,和第三方库解耦

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值