Objective
Android's development ecosystem is growing rapidly, and the architecture and technology used to build Android applications has evolved over the years of Android. Tsing Lung Hall Source code rental (h5.hxforum.com) Penguin 2952777280 source Sale Room Card sale backstage rental as the project continues to update iterations, the application architecture has changed. The technical architecture used is different because of the number of developers, the complexity of the business of the project, the development time of the requirements, the usage level of the application. There is no best architecture, only the most suitable. Through the design to make the program modular, so that the internal module of high aggregation and low coupling between modules. The advantage of this is that in the process of development, developers only need to focus on one point, improve the efficiency of program development, and facilitate the later maintenance of the project. The following summarizes and summarizes the current Android use of the main application architecture and its advantages and disadvantages and use of learning experience, if there is no, welcome to exchange correction.
Mvc
I remember learning from the time of students. NET, the first exposure to the project architecture is called a three-tier architecture. Application layer, business logic layer, and data access layer. The idea of MVC, in fact, is a model of software design that organizes code with a separate approach to business logic, data, and interface display, without the need to rewrite business logic while improving and personalizing the interface and user interaction. The design of the Android project itself is also using the MVC design idea.
? View Layer (views)
The general use of XML file interface description, when used can be very convenient to introduce. It also facilitates the modification of the later interface. The ID of the interface corresponding to the logic does not change, the code is not modified, greatly enhancing the maintainability of the code.
? Control Layer (Controller)
The control layer of Android is primarily the activity layer. The associated view layer interaction triggers and the data presentation logic are encoded in the activity.
? Model Layer
We usually define the corresponding model layer for business data. The operation of the database, the operation of the network, etc. should be processed in the model, of course, business computing and other operations must be placed in the layer
So we have been using the Android default project structure development, mainly in the use of MVC architecture ideas.
Advantages: Simple page presentation is applied, business logic is not complex. High-performance, easy-to-understand code hierarchy
Cons: When the business is complex, activity is very bloated and inconvenient for maintenance and testing
Mvp
MVP This is the main application architecture in our project today, the MVP evolved from an earlier MVC framework, with a certain similarity to MVC: Controller/presenter is responsible for logical processing, model provides data, view is responsible for display. The evolution of the MVP architecture solves the problem of bloated activity code, and when we move complex logic processing to another class (Presenter), the activity is actually the view in the MVP mode, which is responsible for initializing the UI elements. Building UI elements associated with presenter (listener and the like), while also handling some simple logic (complex logic is referred to presenter processing). In the project development, the UI is easy to change, and is diverse, the same data will be displayed in n ways, business logic is relatively easy to change. To make the application more resilient, we want to isolate the UI, logic (UI logic and business logic) and data, and MVP is a good choice. In MVP mode, 3 elements are usually included (plus view interface is 4):
? View: Responsible for drawing UI elements, interacting with users (embodied as activity in Android)
? Model: Responsible for storing, retrieving, manipulating data (sometimes also implementing a model interface to reduce coupling)
? Presenter: As the intermediate link between view and model, handles the responsible logic for interacting with the user.
? View interface: Interface that requires view implementation, view interacts with the presenter via view interface, reduces coupling, facilitates unit testing
Advantages:
- Model and view are completely separated, and the changes do not affect each other
- Use more efficiently, because all of the logical interactions occur in one place-presenter internal
- A preseter can be used for multiple view without the need to change the logic of presenter (because view changes are always more frequent than model).
- More convenient to test. By putting logic in the presenter, you can test the logic out of the user interface (unit test)
Disadvantage: Need to take good presenter, View interface particle size design, easy to appear presenter too simple or complicated.
Mvvm
MVVM is an upgraded version of MVP, where VMs are viewmodel abbreviations, ViewModel can be understood as the data model of the view and presenter, and the interaction between ViewModel and view is done through the data binding. The data binding enables two-way interaction, which further reduces the coupling between the view and the control layer, the separation of concerns is more thorough, and the stress of the activity is reduced.
? The view layer uses an XML file to describe the interface;
? Models (model layer) obtain the data required by the view layer through the network and local database;
? The ViewModel (view-model layer) is responsible for the communication between the view and the models, separating the view and the data.
The two-way binding between view and data is realized through the Android Data binding technology between the view and model, and ViewModel holds the model reference, requests the data through the model method, and obtains the data. Back to ViewModel by callback (callback), the interface is updated in real time due to the bidirectional binding of the ViewModel to the view. At the same time, when the data of interface input changes, the data in ViewModel can be updated in real time due to the bidirectional binding technology, which improves the efficiency of data acquisition.
Using ViewModel to solve the problem that the MVP view (activity) and presenter hold each other's application, the interface is driven by data, and the response interface operation does not need to be passed by view (activity). Changes in data also require no presenter calls to the view (Activity) Implementation, making the process of data transfer more concise and efficient.
Recommended Tutorials:
Proficient in Android Data Binding
Advantages:
? Two-way binding technology, when the model changes, View-model will automatically update, the View will automatically change. It's good to do data consistency.
? Google official support databing, easy to integrate
Disadvantages:
? Data binding makes it difficult for bugs to be debugged
? Data bidirectional binding is not conducive to code reuse and extension
? Reduced reading of the code
Android-architecture
Google in the official example gives a series of different architecture of the app implementation, the project is to show the different ways of architecture app to help developers solve architectural problems. The project implements the same functional app through different architectural concepts and methods.
Google's official MVP Architecture sample Project
Todo-mvp-rxjava
Using Rxjava to process the data flow, and through repository for the centralized management of the data, through the Protocol class xxxcontract to the view and presenter interface for internal inheritance, in the presenter implementation class, The model data can be manipulated. instance, the data acquisition, storage, data state changes are the tasks of the model layer, presenter calls the data processing logic of the layer as needed and passes the callback in when needed. The model, presenter, and view only deal with their respective tasks and realize the principle of single responsibility.
Recommended Tutorials:
Google's official Mvp+rxjava project detailed
Component of
With the promotion of the project, and the development of business. One day you can find that the team needs to develop multiple apps, and many apps have the same business module, the first practice in order to catch the progress of the project may be sticky copy, to the back slowly find more and more arduous, repetitive work.
Slowly with the passage of time, a vicious circle. Slowly found that the project code structure confusion, unclear level, the business technical solutions are not unified, even the basic package structure is also random, are constantly piling up code to add new features, the predecessors dug pit to fill. Visible components have far-reaching implications for continuously iterative projects
- Avoid repetitive wheel building and improve development efficiency
- Reduce coupling and improve reusability
- Maintain the unity of the team's technical solutions
- Easy Maintenance Upgrades
Basic component
Typically, the structure used in the project is as follows:
It doesn't seem to be a problem, but usually some of our libraries are integrated into code in the form of code, and as the project progresses, it slowly discovers some of the more serious problems.
- The business code invades the component code (for example, some global network returns the response, encoding directly in the library, etc.)
- There are no constraints within the team, each integrating different base libraries (examples are loaded with glide, some with imageloader)
- Some third-party components stop updating, project code coupling is high, replacing new schemes is difficult
Therefore, in the process of physical facility Assembly, it is recommended to refer to:
- Independent Library Library (common base component) to avoid direct code integration in the main project, using AAR to reference
- Third-party library calls are best to install a second layer of interfaces for subsequent maintenance upgrades
- Members are dedicated to maintenance and can provide business layer calls in the SDK way
Business modularity
As the project logic continues to grow, is it slow to find that the code compiles faster? (PS: Our current project compiles 2 minutes at a time and has been optimized for processing)
Also when there are multiple projects within the team, have you ever experienced a product manager that lets you move a feature of project A to project B, this time ...
The role of business modularity is obvious.
Tsing Lung Hall Source rental Android development ecosystem developed rapidly