SoFunction
Updated on 2025-04-09

Analysis of Android application architecture ideas

Calculate the days, I have been working for just three years. At the beginning of this article, I will work hard to move forward in various directions that I have thought of before. As a migrant worker who has been moving bricks in the Android application layer for many years, I would like to talk about my views on architectural ideas in the first article. If there is any inappropriateness, please take a picture of the bricks.

The story of building a building (fictional)

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

The contractor A was clean and neat, so he started work with his arms. In order to save money, he hired an all-round worker, and he had to buy materials for building a house and use these materials to build a house. At first, the structure of the lower floor house was simple and could still cope with it. When it came to the complex design needs later, I was busy and often exhausted, which blocked the process of building a house, which made the boss very unhappy. I occasionally asked him to change the structure of the house, and he had to push the entire floor to achieve it, which seriously affected the construction period. The drawings drawn are all disposable and cannot be reused, and they are time-consuming and cost-effective. The developer is following behind his butt with his beard and staring all day long.

After contractor B received the developer's plan, he first convened a meeting to determine the styles of all floors and split them into independent modules. It is divided into each person in charge according to the module, some are those who have formulated floor styles, some are those who are specifically responsible for resource provision, some are those who are responsible for transporting resources, some are those who are implemented in accordance with the predetermined plan, etc. It took more than half a month to assign all tasks and start construction. Although there were a lot of people employed and the previous time was delayed by more than half a month, the construction quickly caught up with the next building. emmm, the developer smiled and nodded. The money was cost-effective, and after finishing, he would use the contractor B.

Not long after, both pieces of land were completed. At this time, the quality inspection began. In Area A, which is a headache, there is a minor problem and a large area of ​​land needs to be demolished for renovation. Some places have been modified but it affects other places. In Area B, a dedicated person is responsible for changing the places with problems.

Later, contractor A wandered among small developers, with low salary and tiring, while contractor B had reached the peak of his life. (Haha, end)

The Peak Tips of Contractor B

Let’s review the construction of the contractor B.

After receiving the project, it did not develop immediately and held a meeting to sort out the needs;

Modules are divided according to requirements and functions, and the corresponding personnel are responsible;

The person in charge of each functional module is managed in a flat manner without mutual constraints;

Similarly, the same is true for the development of our App. We cannot hand over all tasks to Activity like contractor A. We need to create an App in layers like a contractor B. You can learn about clean Architecture, which divides the App application into three layers, internal-middle-outside, and then 4 managers will manage them separately.

Layering guidelines:

  • Abstract from outside to inside
  • The inner layer does not understand the layer, the outer layer depends on the inner layer
  • Clear division of labor and independent of each other

Let’s explain the first point first. In the past, when we developed apps, we started with the interface and then finally reached the business logic. Now, we have to turn around and when receiving the demand, we must first clarify what the entity is

(For example, for example, the login function, the entity it describes is the user User), and then what behavior does it do (such as login, log out of userCase). Finally, we will realize specific functions.

The inner layer does not understand the outer layer, so take login as an example. In the inner layer, you only need to know that the user has login and logout behavior. As for how it performs these behaviors, the inner layer does not need to know. However, in contrast, if the outer layer wants to realize the inner layer's behavior, you need to know what behaviors are in the inner layer, so a dependency is created. The inner layer can exist independently, while the outer layer must rely on the inner layer.

The division of labor is clear and independent of each other. It means that the functions of each module exist independently. For example, login and registration functions are independent of each other, and each performs its own duties and cannot interfere.

4 managers

  • domain: defines abstract entities, core business logic, and data output interface. This layer is pure java code, it is recommended to create java module directly.
  • data: data management, divided into local storage (sqlLite, sharedpreferences), and server API.
  • device: related to Android underlying layer, such as notifications, Bluetooth, sensors, etc.
  • app: The level we are most familiar with, you can choose MVP and MVVM mode to implement the UI interface according to your own preferences.

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

For the app layer, taking MVP as an example, first implement all the behaviors defined by the domain layer in presenter, data layer and device layer assistance. Finally, implement the UI interface and complete the functions.