资料详情

基于MVP的 Android App架构设计与案例分析 毕业论文+任务书+答辩PPT

头像

android

编号:3255

摘 要

随着 Android 客户端 App 的飞速发展,简单的 MVC 分层架构早已不符合当 下开发的需求,现在的 App 具有开发上线周期短,需求变化多,功能体量多跨度大, 更新周期短,适配机型多,合作开发人员多等特点。

那么,对于现在体积庞大的 App,本文设计了一个立体的架构。本架构的设计 从横向,纵向和延伸性上考虑。纵向主要分解流程;横向主要分解业务,和开发期间 的功能复用;延伸性上本架构充分考虑了架构的升级和发展潜力,降低架构演进成本。

纵向上,本架构实现了合理分层。每个组件进行分层例如 MVP ; App 整体被分 为驱动层,lib  层,架构层,App  层,保证了底层架构对于上层 App 的控制力。

横向上,本架构采用组件化和模块化设计。组件化将每个部分进行细粒化的分离, 对每个具体业务进行切割隔离,并且实现组件之间的树形依赖管理,使底层组件可以 最高效的被上层业务组件复用;赋予组件生命周期管理,并且组件层级之间使用 DI 进行依赖拼装。在业务量大的情况下,组件提供了模块化进一步切割业务及功能,辅 以页面路由器进行模块间跳转,对于大型 App 来说,组件化使各个团队在开发期间 的隔离分工;App 落地运行期间子模块按需加载,即功能组件的懒加载,为用户节 省资源;除此之外利于动态增加功能模块。

延伸性上,本架构将架构的底层设计高度抽象化,严格遵循面向接口,保证了架 构的演进升级。对于上层 App,现在 App 对于更新的需求日益增长,架构集成了增 量更新组件,Bugfix 上,架构也集成了动态热补丁。

同时本架构也经过了实际开发案例的检验,最后给出了已经上线的实际开发案例 检验了本架构优越性。

关键词:Android;架构设计;App 开发;组件化;模块化;分层;MVP.


Abstract

With the development of the application of the android client,the mvc witch a simple layered architecture can not meet the current complex needs.Nowadays, app has many traits such as short circle of the development,frequent change of requirements,complex in function,frequently updated, many types of adaptation and multi person cooperation.

So, for the now bulky App, this article designed a three-dimensional architecture. The design of this architecture is considered in terms of landscape, longitudinal and extensibility. The main decomposition process; the main decomposition of the main business, and the development of the functional reuse; extension of the framework of the architecture to take full account of the upgrade and development potential, reduce the evolution of the cost of architecture.

For vertical, the architecture to achieve a reasonable layer. Each component is layered, such as MVP; App overall is divided into the driver layer, lib layer, architecture layer, App layer, to ensure that the underlying architecture for the upper App control.

For horizontal, the architecture uses modular and modular design. The component separates each part by fine-grained separation, isolates each specific business, and implements tree-dependent management between components so that the underlying components can be most efficiently reused by the upper business components; Cycle management, and the use of DI between the component level to rely on the assembly. In the case of large traffic, the components provide a modular further cutting business and functions, supplemented by page routers to jump between modules, for large App, the components of the various teams during the development of the division of labor; During the sub-module on-demand loading, that is, lazy loading of functional components  for users to save resources; in addition to the dynamic function of the module.

For extensibility, the architecture of the architecture of the underlying design highly abstract, strictly follow the interface-oriented, to ensure the evolution of the architecture upgrade. For the upper App, App is now growing demand for updates, the architecture integrates incremental update components, Bugfix, the structure also integrates  dynamic hot patch.

At the same time the structure has also been the actual development of the case test.


Keywords:Android;Architecture;Design;ApplicationDevelopment;Component-based;

Bundle-based;Layered architecture;MVP.


目 录


第一章 绪论 1

1.1  研究背景 1

1.2 Android 架构的现状和发展 1

1.2.1 Android 架构的初期状态 1

1.2.2 Android 4.0  之后,Fragment  的引入 1

1.2.3 MVP & MVVM 2

1.2.4  事件驱动编程 2

1.2.5 RxJava 带来的革命 2

第二章 架构需求分析 3

2.1  需求目标 3

2.1.1  目标产品 3

2.1.2 目标用户(开发者) 3

2.2  开发需求 3

2.2.1  开发期的功能需求 3

2.2.2  开发期的质量需求 4

2.3  用户级需求 4

2.3.1  用户级功能需求 4

2.3.2  运行期质量需求 5

2.4  需求总结 5

第三章 架构整体设计 6

3.1  架构逻辑设计 6

3.1.1  架构图 6

3.1.2  架构结构划分 6

3.1.3  架构特点 7

3.1.4  架构核心 Common 7

3.2  项目开发期间架构设计 9

3.2.1  工程结构 9

3.2.2  使用本架构构建 App 9

3.2.3  编译期间依赖关系 11

3.2.4  模块隔离开发 11

3.3  运行期间架构 12

3.3.1  运行期间的模块加载升级 12

3.3.2  运行期组件依赖 12

3.3.3  页面导航和业务服务导航 12

第四章 分层架构 13

4.1  分层概述 13

4.2 MVC 分层架构 13

4.2.1 MVC 简介 13

3.2.2 Model 模型层 14

4.2.3 Controller 控制器 15

4.2.4 View  层 15

4.2.5 MVC 所存在的问题 15

4.3 MVVM 分层架构 17

4.3.1 MVVM 简介 17

4.3.2 MVVM 各层 17

4.3.3 DataBinding 原理简介 18

4.3.4 MVVM 缺点 19

4.4 MVP 分层架构 19

4.4.1 MVP 简介 19

4.4.2 Model 层设计 20

4.4.3 View  层设计 20

4.4.3 Presenter  层设计 21

4.4.4 MVP  的统筹 协议层设计 21

4.4.5 MVP 的优缺点 22

4.4.6 MVP  与 MVC 的不同。 22

第五章 组件化 24

5.1  组件化介绍 24

5.2  本架构中组件的实现 24

5.3 Component 的依赖 25

5.4 Component 的生命周期 25

5.5 MVP Component 26

5.6 API Component 27

5.7 AppComponent 28

5.7.1 AppComponent 含义 28

5.7.2  各个基础组件 29

5.8 组件管理器 ComponentManager 31

第六章 DI  依赖注入 33

6.1  依赖注入定义 33

6.2  依赖注入意义 33

6.3 Android  中的依赖注入 Dagger2 34

6.3.1  简介 34

6.3.2 Dagger2 中的重要概念 34

6.4  本架构中的依赖注入 35

6.4.1 MVP 三层依赖组装 35

6.4.2 App 全局组件依赖 36

6.4.3  业务组件依赖拼装 37

第七章 AOP 面向切面编程 40

7.1 AOP 的定义 40

7.2  在 Android  上使用 Aspectj  实现 AOP 40

7.3  动态织入实现原理 41

7.4 AOP 在本架构中的使用 42

7.4.1  动态权限检测 42

7.4.2  登陆检测 43

7.4.3  性能检测 & Log 43

7.4.4  异步与主线程 44

第八章 Bundle 模块化容器化 46

8.1  定义 46

8.2  意义 46

8.3 Atlas & Small 46

8.3.1  简介 46

8.3.2  原理 47

8.4  本架构中的模块化 48

第九章 Router  页面路由 50

9.1  背景 50

9.2 Intent 导航遇到的问题 50

9.3  意义 50

9.4  页面路由的使用 51

9.5  页面路由的原理及实现 52

9.5.1  页面发现 52

9.5.2  页面分发 53

第十章 事件驱动 54

10.1  事件驱动定义 54

10.2  事件驱动意义 54

10.3  事件驱动框架原理 54

10.4  事件框架的实现 EventPoster 56

10.4.1 EventPoster 优势简述 56

10.4.2  模块 Handler  以及分发 57

10.4.3  性能优化 57

10.4.4  防止 Leak 58

第十一章 框架原理及实践 59

11.1  自己动手实现 JSON ORM  框架 59

11.2  图像异步加载框架原理及实现 63

11.2.1 Cache 63

11.2.2 线程池 64

11.2.3 图片压缩 64

11.2.4 其他优化 64

11.3 Http  请求框架 Retrofit 65

11.3.1 原理 65

11.3.2 源码分析 65

第十二章 案例实践 68

12.1 案例简述-数读 68

12.2 需求简述-数读 68

12.3 重构之前的程序结构-数读 68

12.4 重构后的程序结构-数读 69

12.4.1 架构裁剪-数读 69

12.4.2 UML 类图-数读 70

12.4.3 主要功能需求-数读 70

12.4.4  重构带来的改变 73

结 论 75

致 谢 76

参 考 文 献 77