Android MVP模式的学习
2016-10-09 17:36
344 查看
概要
这个示例是众多的变体。它展示了一个简单的实现Model-View-Presenter模式与体系结构框架。它使用人工依赖注入为存储库提供本地和远程数据源。异步任务处理回调。Note: in a MVP context, the term “view” is overloaded:
The class android.view.View will be referred to as "Android View" The view that receives commands from a presenter in MVP, will be simply called "view".
Fragments
It uses fragments for two reasons:The separation between Activity and Fragment fits nicely with this implementation of MVP: the Activity is the overall controller that creates and connects views and presenters. Tablet layout or screens with multiple views take advantage of the Fragments framework.
Key concepts
There are four features in the app:Tasks 负责: view 和 presenter 之间定义一个契约(自定义 View 也放在task下) TaskDetail 负责:一个 Activity 负责创建fragment和presenters AddEditTask 负责: Fragment 实现 View 的接口
官方实现的示例
Each feature has:
1.A contract defining the view and the presenter view 和 presenter 之间定义一个契约 2.An Activity which is responsible for the creation of fragments and presenters 一个 Activity 负责创建fragment和presenters 3.A Fragment which implements the view interface. Fragment 实现 View 的接口 4.A presenter which implements the presenter interface Presenter 实现 presenter 的接口
In general, the business logic lives in the presenter and relies on the view to do the Android UI work.
The view contains almost no logic: it converts the presenter’s commands to UI actions and listens to user actions, which are passed to the presenter.
Contracts are interfaces used to define the connection between views and presenters.
Dependencies
Common Android support libraries (com.android.support.*) Android Testing Support Library (Espresso, AndroidJUnitRunner…) Mockito Guava (null checking)
相关文章推荐
- Android-缓存网络图片(MVP模式)学习笔记
- Android学习探索之运用MVP设计模式实现项目解耦
- ANdroid mvp 模式 优秀的学习demo
- 【Android学习】两种MVP模式的学习(一):谷歌例子的简单学习
- Android学习探索之运用MVP设计模式实现项目解耦
- 学习笔记:Android里面的MVC模式与MVP模式
- 学习android的MVP模式
- Android 学习之MVP模式
- 【项目架构】Android MVP 和MVVM框架模式 学习实例Demo之mvp篇
- Android学习之浅谈对MVC模式和MVP模式的理解
- android:MVP模式学习
- Android学习探索之运用MVP设计模式实现项目解耦
- Android学习 StateMachine与State模式
- Android源码学习之装饰模式应用
- Android学习之Adapter(适配器)源代码分析与观察者模式的运用(一)
- Android源码学习之单例模式应用
- Android源码学习之装饰模式应用
- Android学习 StateMachine与State模式
- Android源码学习之组合模式定义及应用
- Android学习之Adapter(适配器)源代码分析与观察者模式的运用(一)