Android官方MVP架构解读,todoapp: Android官方MVP架构示例项目解析 todo-mvp(mvp基础架构示例)...

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.

6f3e43c34610747ff7ee31081da2bc70.png

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

TaskDetail

AddEditTask

Statistics

Each feature has:

A contract defining the view and the presenter

An Activity which is responsible for the creation of fragments and presenters

A Fragment which implements the view interface.

A presenter which implements the presenter interface

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)

Features

Complexity - understandability

Use of architectural frameworks/libraries/tools:

None

Conceptual complexity

Low, as it's a pure MVP implementation for Android

Testability

Unit testing

High, presenters are unit tested as well as repositories and data sources.

UI testing

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.

-------------------------------------------------------------------------------

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值