Android-Architecture学习篇一:基础的MVP架构

1 前言

作为google官方的安卓架构,

官方地址

,很有学习的必要!

2 基础的MVP架构

todo-mvp/- Basic Model-View-Presenter architecture.

Android-Architecture学习篇一:基础的MVP架构_第1张图片

3 app结构分析

  app主要有四个功能:Tasks、TaskDetail、AddEditTask、Statistics

Android-Architecture学习篇一:基础的MVP架构_第2张图片

每四个功能主要由Contract、Activity、Fragment、Presenter

4 一个小功能的Mvp主要组成介绍

Contract:A contract defining the view and the presenter。View模块和Presenter模块的合同,相当于View模块和Presenter模块的结合。

Android-Architecture学习篇一:基础的MVP架构_第3张图片

Presenter:A presenter which implements the presenter interface。很简单,就是实现Presenter的接口,至于怎么实现,这里不考虑细节。

Fragment:A Fragment which implements the view interface。Presenter实现Contract中Presenter功能,而Fragment就是实现Contract中View的功能,同样不考虑其实现的。

Activity:An Activity which is responsible for the creation of fragments and presenters。负责创建所有fragments和presenters。

5 理解

In general, the business logic lives in the presenter and relies on the view to do the Android UI work.

在一般情况下,业务逻辑处于在Presenter,并依赖于VIew来实现的Android UI工作。

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.

View Contains 视图容器没有任何逻辑实现。它将Presenter的命令转化为用户界面操作,并且监听用户操作然后传递给Presenter

Contracts are interfaces used to define the connection between views and presenters.

Contracts是用来定义Views和Presenters之间的连接接口。

6 总结

MVP的基本结构就是这样,这里没有提到Model,其实Model就是获取数据的模型。

你可能感兴趣的:(Android-Architecture学习篇一:基础的MVP架构)