Android MVC Design Pattern

MVC definition?
MVC (Model View Controller), is the abbreviation of model (Model) view (view) controller (controller), a software design pattern, used to organize code with a method of separating functional modules and data modules

In our Activity,
M: handle business logic
V: handle the part of data display
C: handle user interaction through Activity

If you are asked in an interview what MVC is, you answer that, with a small example at the end?
In the process of Activity development, the more popular development framework once used the MVC framework mode. The advantage of using the MVC framework mode is to facilitate the separation of UI interface display and business logic. Specifically, the M layer Model layer is used for business logic processing. For example, we can perform some database operations, network operations, some complex operations or some time-consuming tasks can be processed in the Model. The View layer is used to handle the data display part of the application. In MVC, the xml layout is regarded as the view layer, and the C layer is used to deal with user interaction issues in the Activity. Therefore, it can also be considered that the Activity is the controller, the Activity controller. By reading the interface data of the View layer, and then handing the data to the interface for display, this is the MVC framework pattern

MVC features?
Advantages:
1) Low coupling (the degree of code correlation between modules is not very high, various business modules can be disassembled, and the three layers of MVC can be analyzed to achieve the purpose of decoupling and reduce the interaction between modules)
2) Extensible and good for maintenance (due to low coupling, when adding extension code or iterating, you don’t need to modify the previous code too much to reduce the occurrence rate of bugs and online crashes)
3) Module responsibilities are clearly divided

Disadvantages:
1) Too much code in ActivityContronller, redundant
2) Not suitable for small, medium-scale applications
3) View layer and Model layer are coupled to each other, not suitable for development and maintenance

Actual combat:
The login interface example
Activity is used as the C layer to obtain the data input in the edittext in the xml layout of the View layer, passed to the M
layer for data request, and the request result is called back to the C layer Activity, and then the C layer updates the V according to the request result. Layer data or interface

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325602977&siteId=291194637