On Android Clean architecture

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/Kennethdroid/article/details/90178944

The original article first appeared in the public micro-channel number "byte floating"

Android architecture used mainly MVC, MVP, MVVM and Clean. Above architecture design pattern is no absolute good or bad, the key depends on the specific application scenarios. More about MVC, MVP and MVVM presentation can refer to MVC, MVP & MVVM

What is the Clean architecture?

Robert C. Martin (Uncle Bob)

Clean architecture by Uncle Bob, published in 2012, the architecture is designed for Web App.

Uncle Bob summed up in common, and the ultimate goal of a variety of system architectures, and propose only uphold the principle of hierarchical and dependent rule, proposed Clean architectural thought.

Analysis of Clean Architecture

One-way dependence

Clean architecture, images from Robert C. Martin (Uncle Bob)

Clean architecture dependencies between the layers is unidirectional, only the outer layer is dependent on the inner layer.

MVP VS Clean

Images from Google

Android can be seen from the figure achieved Clean architecture is actually more popular MVP architecture transformation.

The MVP as Clean View and Presenter layer architecture Presentations Layer, new Domain Layer all the business logic processing. Model layer in MVP function is weakened, as the only interface to the external Data Layer, there are no business logic. Generally independent data model each floor.

Clean the Presentation layer

It includes the following categories:

  • Presenter View layer and related classes, of course, you can transform the MVVP framework foundation.
  • Mapper classes, the data model layer is responsible for Domain convert Presentation data model.
  • Exception class encapsulating layer is present.

Clean the Domain layer

Clean the Domain layer

Domain layer does not rely on third-party libraries and libraries Android, unit testing can be done independently.

It includes the following categories:

  • Use Cases (Interactor) category, is responsible for the completion of an operation against Data layer. (Such as access to movie list, acquiring a movie can be regarded as the detail info Use Case 2 or Interactor).
  • Mapper classes, is responsible for converting the data model to the data model layer Data Domain layer.
  • Exception class encapsulating layer is present.

Clean the Data Layer

Clean the Data Layer

Pictures from Robert C. Martin (Uncle Bob)

This figure is enough to explain everything.

It includes various API interfaces, corresponding to the main database operations, data manipulation, and network file operations, some unusual class packages.
Mapper classes responsible for converting network data model is a data model Data layer.

Note that only the interface layer provides Data, no business logic.

Android Clean architecture implementation

A Clean architecture and Retrofit, RxKotlin, Dagger framework-based implementation Kotlin for Android App .

reference

Contacts and exchanges

Micro-channel public number of
My public number
individual micro letter
My WeChat

Guess you like

Origin blog.csdn.net/Kennethdroid/article/details/90178944