明白Android中的MVP

2016-11-04  本文已影响0人  槐树向北

我找到了官方讲解MVP的sample(代码示例)
官方示例地址

于是我下载了最基本的一个实现MVP的样例代码.
最基本的TODO-MVP

然后我对他下面的ReadMe做了全部翻译.

TODO-MVP

Summary

This sample is the base for many of the variants. It showcases a simple
implementation of the Model-View-Presenter pattern with no architectural
frameworks. It uses manual dependency injection to provide a repository with
local and remote data sources. Asynchronous tasks are handled with callbacks.
这个样例是那些复杂变体的基础.它展示了一个没有经过任何构建框架装饰过的实现了Model_View_Presenter的样例.它使用手工的依赖注入来提供本地和远程数据源的仓库.异步任务来处理回调.


DiagramDiagram

Note: in a MVP context, the term "view" is overloaded:
提示:在一个MVP的上下文里,术语"View"是过载的.

Fragments

It uses fragments for two reasons:
使用fragmen有两个原因:

Key concepts 关键概念

There are four features in the app:
这个app有四个功能:

Each feature has:
每个功能都有:

In general, the business logic lives in the presenter and relies on the view to
do the Android UI work. 通常,业务逻辑存在于presenter里面并且依赖于view,它用来完成AndroidUI的工作.

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层几乎不包含任何逻辑:他转换presenter的逻辑给UI的动作,他还监听用户的动作并且传递给presenter.

各种规定都是接口,用来定义views和presenters的连接的.
Contracts are interfaces used to define the connection between views and
presenters.

Dependencies 依赖.

Features功能

Complexity - understandability

概念的复杂性

Use of architectural frameworks/libraries/tools:

使用的构建, 框架/库/工具

None 没有?

Conceptual complexity

概念的复杂性.
Low, as it's a pure MVP implementation for Android
这是一个为Android的纯MVP实现.

Testability

可测试性

Unit testing

单元测试
High, presenters are unit tested as well as repositories and data sources.
高,presenters都是经过单元测试的,针对存储仓库和数据源.

UI testing

UI 测试
High, injection of fake modules allow for testing with fake data
高注入的假模块允许使用伪造数据测试.

Code metrics

代码矩阵.

Compared to a traditional project with no architecture in place, this sample
introduces additional classes and interfaces: presenters, a repository,
contracts, etc. So lines of code and number of classes are higher in MVP.

相比传统的项目没有构建的地方,
这个示例引入了额外的类和接口:presenters,一个仓库,契约等。所以类的代码的行数和数量在MVP模式里变得更多了。

-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Java                            46           1075           1451           3451
XML                             34             97            337            601
-------------------------------------------------------------------------------
SUM:                            80           1172           1788           4052
-------------------------------------------------------------------------------

Maintainability

可维护性

Ease of amending or adding a feature

易于修改或添加功能
High.

Learning cost

学习花费

Low. Features are easy to find and the responsibilities are clear. Developers
don't need to be familiar with any external dependency to work on the project.
低.功能都很好找,并且他们的职责都很明确.要这个项目工作,开发者不必熟悉外部的依赖.

2016-11-4 22:20:17
用时:两个番茄

上一篇下一篇

猜你喜欢

热点阅读