MVC for Android

Source: Internet
Author: User

In Android development, the more popular development framework pattern is the MVC framework pattern, the advantage of adopting MVC pattern is that it is easy to display and business logic of UI interface, and data processing is separated. So the question is, what code in the development of the Android Project will act as the m,v,c role? The following is a brief anatomy of MVC for Android based on the specific structure of the Android project.

M (model) models layerSuitable to do some business logic processing, such as database access operations, data request operations on the network, complex algorithms, time-consuming tasks should be in the model inside, of course, business computing and other operations must be placed on the layer.
V (View) display layerThe part of the application layer that handles the display of data. Android does a good job of pulling out the display layer and putting it in the "res/" directory as XML, so the XML layout in Android can be treated as a V-layer, displaying the data results of the model layer and receiving the information entered by the user.
C (Controller) control layerIn Android, activity handles user interaction issues, so it can be assumed that activity is a controller, activity reads data from the V-View layer, controls user input, and sends data requests to the model layer. Control is the duty of activity, you just tell the activity what to do, and as for what to do, it's the model layer. This also implies that you do not write too much logic code in the activity, to be processed by the activity delivery model business logic layer, another reason is that the activity in Android response time is 5s, if the time-consuming operation is placed here, the program is easy to be collected.
What happens if you don't use MVC?
    • The most obvious disadvantage of this is the excessive coupling. Imagine that, in the early stages of design, there was no strict layering of MVC, and in development, when a method or a layout needs to be changed, because of the excessive coupling between layers and layers, you will be faced with the "reaching" modification process. If we design an application based on MVC, we can only modify the corresponding layer to achieve our goal.
    • Difficult division of labor. In the case of MVC, programmers have a headache and waste a lot of effort on how to design UI user interface, instead of focusing on the writing of core code and reducing development efficiency. If you follow MVC, you can give the view layer to the art process, the programmer can better care about the writing of the core code, no longer bothered by the cumbersome layout.
    • Difficult to maintain. In the case of not using MVC, even if the project can be successfully completed, but in the development process, the user may be dissatisfied with a module, need to modify or remove, sometimes need to add new modules, such things, for the process of not using the MVC Framework model of the program, it will be a headache.
    • The Android system specifically provides files such as Strings.xml, colors.xml types in the "res/values/" directory, which can be used to write our constant values into an XML file for easy invocation. This not only saves resources, but also facilitates the management of resources. If a variable needs to be modified, the Strings.xml file can be modified directly. Otherwise, we need to modify all the code in the entire application that uses that variable.

MVC for Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.