Analysis of Android Application Architecture Thought

  • 2021-09-12 02:20:59
  • OfStack

Counting the days, I have been working for just three years. At the beginning of this article, I will work hard to advance in all kinds of directions that I thought of before. As a migrant worker who has moved bricks in Android application layer for many years, I would like to talk about my own views on architecture thought for the first time. If there is anything wrong, please pat bricks.

The Story of Gai Lou (Fictional)

There is one piece of land and two areas, and the developer has two contractors responsible for the development.

A, the contractor, worked cleanly and started work with open arms. In order to save money, he hired an all-round worker. He had to buy materials for building houses and build houses with these materials. At first, the structure of the ground floor house was simple and it could be handled. When it came to the complicated design requirements, it was busy and often exhausted, which blocked the process of building the house and made the boss very unhappy. Occasionally, he was asked to change the structure of the house. He had to push the whole floor to achieve it, which seriously affected the construction period. Drawing drawings are once, can not be reused, time-consuming and money-consuming, developers all day blowing beard glaring behind the buttocks.

After the contractor B got the developer's plan, he first called his younger brother to have a meeting, determined the styles of all floors, and split them into independent modules. According to the module, it is divided into various responsible persons, including those who formulate floor styles, those who are specially responsible for providing resources, those who are responsible for transporting resources, and those who are implemented according to the predetermined plan. It took more than half a month to assign all the tasks and start construction. Although people hired a little more, the previous time was delayed for more than half a month, but 1 started work and soon caught up with the next building. emmm, the developer smiled and nodded. The money was cost-effective. After the event, the contractor B was used.

Soon after, both plots were completed. At this time, the quality inspection began. In the troublesome A area, there is a small problem that needs to be demolished and transformed. Some places have been improved but affected other places. On the other hand, in the B area, a special person is responsible for changing the problematic places.

Later, the contractor A wandered in various small developers, and his salary was low and tired, while the contractor B had already reached the peak of his life. (Ha ha, end)

Peak cheats of contractor B

Let's review the Gai Lou of the contractor B.

After receiving the project, there was no immediate development and meeting to sort out the requirements;

Divide modules according to needs and functions, and the corresponding personnel are responsible for them;

The person in charge of each functional module has flat management without mutual constraints;

Similarly, the development of our App is the same reason, and we can't give all the tasks to Activity like the contractor A1. We want to create App in layers like contractor B1. You can learn about clean Architecture. Here, App application is divided into three layers, inside-middle-outside, and then four managers manage them respectively.

Criteria for stratification:

Abstraction from outside to inside The inner layer does not understand the layer, and the outer layer depends on the inner layer Clear division of labor and mutual independence

First, let's explain article 1 under 1. In the past, when we developed App, we started with the interface, and then finally went to the business logic. Now we have to reverse it. When we receive the demand, we must first clarify what the entity is

(For example, the login function, which describes the entity as the user User), and then what it does (such as login, logout of userCase). Finally, it comes to the realization of specific functions.

The inner layer doesn't know the outer layer, or take login as an example. The inner layer only needs to know that the user has login and logout behaviors. As for how it carries out these behaviors, the inner layer doesn't need to know, but on the contrary, if the outer layer wants to realize the inner layer's behaviors, it needs to know what behaviors the inner layer has, which leads to dependencies. The inner layer can exist independently, while the outer layer must depend on the inner layer.

The division of labor is clear and independent, which means that the functions of each module exist independently, for example, the login and registration functions are independent of each other, and they perform their respective duties and cannot be replaced by others.

4 managers

domain: Defines abstract entities, core business logic, and data output interfaces. This layer is pure java code, and it is recommended to create java module directly. data: Data management, divided into local storage (sqlLite, sharedpreferences) and server Api. device: Related to the underlying Android, such as notifications, Bluetooth, sensors, and so on. app: We are most familiar with the hierarchy, and we can choose MVP and MVVM mode according to our preferences to realize UI interface.

App Development Process

The domain layer defines abstract entities and sets their corresponding behaviors. In the data layer, data support is given device layer, developed on demand

app layer, taking MVP as an example, first implements all behaviors defined by domain layer in presenter, and data layer and device layer assist. Finally, the UI interface is realized and the functions are completed.


Related articles: