android jni示例_Android体系结构示例:层和模块

android jni示例

介绍 (Introduction)

Since the very early releases of Android until today, the architecture of Android applications has evolved to support production-quality apps that can be developed with robust designs, testing capabilities, and maintainable code. This article explains how the architecture of an Android application can be seen in two different dimensions: the logical dimension and the modularized dimension.

从Android的早期发布到今天,Android应用程序的体系结构已发展为支持可通过可靠的设计,测试功能和可维护的代码进行开发的生产质量的应用程序。 本文介绍了如何从两个不同的维度看待Android应用程序的体系结构:逻辑维度和模块化维度。

The article and the explanations are given based on MoviesPreview, which is an application that allows a user to browse the data exposed by The Movie DB API to see different information about movies, actors/actresses, and some other features. The full code of the project can be found in the following link:

本文和说明是基于MoviesPreview给出的,该应用程序允许用户浏览The Movie DB API公开的数据,以查看有关电影,演员/女演员和其他一些功能的不同信息。 该项目的完整代码可在以下链接中找到:

逻辑维度 (The Logical Dimension)

I decided to name this dimension the Logical Dimension since it explains the architecture from a logical point of view: what is the logic that each layer of the architecture is containing.

我决定将此维度命名为“逻辑维度”,因为它从逻辑的角度解释了体系结构:体系结构的每一层所包含的逻辑是什么。

From this dimension, the application is architected in three different layers, sitting one on top of the other: the View Layer, the Domain Layer, and the Data Layer.

从这个角度出发,该应用程序被构造为三个不同的层,一层位于另一层之上:视图层,域层和数据层。

  • The View Layer has the responsibility of rendering the view state of the application. The view state of the application is the result of the execution of the application’s use case and its adaptation to ‘UI Language’. A detailed explanation can be found in this article.

    视图层负责呈现应用程序的视图状态。 应用程序的视图状态是执行应用程序用例并适应“ UI语言”的结果。 可以在本文中找到详细的说明

  • The Domain Layer has the responsibility of executing the logic encapsulated in the application’s use cases. Each Use Case represents a feature that the application provides to the user. More information can be found here.

    域层负责执行封装在应用程序用例中的逻辑。 每个用例代表应用程序提供给用户的功能。 在这里可以找到更多信息。

  • The Data Layer takes care of abstracting the upper layers of the different data sources that can provide information to the application. This Medium article contains a detailed explanation of the repository pattern used in this layer.

    数据层负责抽象化可以为应用程序提供信息的不同数据源的上层。 这篇中型文章详细介绍了此层中使用的存储库模式。

All three layers manage a common language: the domain classes, which is the actual representation of the entities that are part of the business model of the application. At the same time, layers at the top and the bottom of the image ‘speak’ their own language: the View Layer speaks View State, the Data Layer speaks Data Classes. This is because the implementation of each layer has different dependencies from frameworks and platforms. Each layer takes care of translating or adapting the domain language to its own domain.

所有这三层都管理一种通用语言:域类,这是作为应用程序业务模型一部分的实体的实际表示。 同时,图像顶部和底部的层“说”自己的语言:视图层讲视图状态,数据层讲数据类。 这是因为每一层的实现都与框架和平台具有不同的依赖关系。 每一层都负责将领域语言翻译或调整为适合其自己的领域。

One key aspect of this layered architecture is that the domain layer knows nothing about the platform: it is agnostic of the fact that the application is running in an Android platform, making it portable to other platforms. This can be even clearer in the fact that access to specific platform features or implementations (like Context access or connectivity detection) is found in the top layer or the bottom layer. The Domain Layer has no dependencies on these kinds of things.

这种分层体系结构的一个关键方面是,域层对平台一无所知:它与应用程序运行在Android平台上并使其可移植到其他平台这一事实无关。 在顶层或底层可以找到对特定平台功能或实现的访问(例如上下文访问或连接检测),这一点甚至可以更加清楚。 域层不依赖于此类事物。

模块尺寸 (The Module Dimension)

I use this name to define a dimension that analyzes the architecture of an application from the Gradle modules perspective and the relations between those modules.

我使用这个名称来定义一个维度,该维度从Gradle模块的角度以及这些模块之间的关系来分析应用程序的体系结构。

As described in this Google I/0'19 presentation, modularization is a software design technique that helps separate functionality in independent modules, allowing the modules to focus on specific functionalities. Using this software design technique, you get a great number of benefits (scalability, maintainability, faster compilation, the potential for Dynamic Features, etc).

如本Google I / 0'19演示中所述,模块化是一种软件设计技术,可帮助将独立模块中的功能分开,从而使模块专注于特定功能。 使用这种软件设计技术,您将获得许多好处(可伸缩性,可维护性,更快的编译速度,潜在的动态功能等)。

I decided to follow a mix between feature modularization and layer modularization in which each layer described in The Logical Dimension is narrowed to a specific module but also each feature is contained in its specific Gradle module:

我决定遵循功能模块化和层模块化之间的混合方式,其中在“逻辑维”中描述的每一层都缩小到一个特定的模块,但是每个功能都包含在其特定的Gradle模块中:

Image for post

:app : this is the application module, that contains the main Activity along with other features that are bonded to the home screen. It depends on:

:app :这是应用程序模块,包含主要的Activity和绑定到主屏幕的其他功能。 这取决于:

  • :features / to be able to redirect to each specific feature from the home screen.

    :features /以便能够从主屏幕重定向到每个特定功能。

  • :mpdomain / the home screen executes Use Cases. Therefore, it needs to have access to the domain module.

    :mpdomain /主屏幕执行用例。 因此,它需要有权访问域模块。

  • :mpdata / it depends on this module, but not directly. This means that it is not consuming code from the module, but it needs the code in there to inject dependencies since the Dependency Injection framework (Dagger) is located in the :app module.

    :mpdata /它取决于此模块,但不直接取决于此模块。 这意味着它不使用模块中的代码,但由于依赖注入框架(Dagger)位于:app模块中,因此它需要其中的代码来注入依赖。

:features : this is actually the representation of the conjunction of all modules that contains the features of the application. It depends on :mpdomain to be able to execute the Use Cases that support each feature.

:features :这实际上是包含应用程序功能的所有模块的并集的表示。 它取决于:mpdomain才能执行支持每种功能的用例。

:mpdomain : contains all the domain objects definition (the model) along with the Use Cases and the repository definitions.

:mpdomain :包含所有领域对象定义(模型)以及用例和存储库定义。

:mpdata : contains the implementation of the repositories defined in :mpdomain and the data sources implementation to access the data needed by the application.

:mpdata :包含:mpdomain中定义的存储库的实现以及访问应用程序所需数据的数据源实现。

:mpcommon : this is a common module used to contain code that is common to the entire application (like date-utilities). All the application’s modules have a dependency on this module.

:mpcommon :这是一个通用模块,用于包含整个应用程序通用的代码(如date-utilities)。 应用程序的所有模块都对此模块具有依赖性。

:mpdesign : this module contains code that is specific to the UI of the application, such as custom views and extension functions related to views. It also contains all the resources that are used by the application, like styles, colors, dimensions, etc. All modules that have UI code are depending on this module.

:mpdesign :此模块包含特定于应用程序UI的代码,例如自定义视图和与视图相关的扩展功能。 它还包含应用程序使用的所有资源,例如样式,颜色,尺寸等。所有具有UI代码的模块都取决于此模块。

:mptestutils : this is a special module that contains utilities that are specific to Unit Tests, like JUnit5 extensions. This module is not present in the graphic above for simplicity, but all other modules of the application have a dependency on this module to be able to execute Unit Tests.

:mptestutils :这是一个特殊的模块,其中包含特定于单元测试的实用程序,例如JUnit5扩展。 为了简单起见,该模块未在上图中显示,但是应用程序的所有其他模块都依赖于此模块才能执行单元测试。

翻译自: https://medium.com/swlh/android-architecture-example-layers-and-modules-19ecbfa57264

android jni示例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值