MVC Architecture Design Reference

Source: Internet
Author: User

MVC (Model-view-controller): M refers to the logical model, v refers to the view model, and C is the controller. A logical model can be used for a variety of view models, such as a batch of statistical data you can use a histogram, pie chart to represent. A view model can also be used for multiple logical models. The purpose of using MVC is to separate the implementation code for M and v so that the same program can use different representations, whereas C exists to ensure the synchronization of M and V, and once m changes, V should be updated synchronously, which is exactly the same as the Observer pattern in design mode.

MVC benefits: From the user's point of view, users can choose their own appropriate way to browse the data according to their own needs. For example, for an online document, you can choose to read it as an HTML page, or you can choose to read it in PDF mode. From the developer's point of view, MVC separates the logic layer of the application from the interface, and the biggest benefit is that the interface designer can directly participate in the interface development, the programmer can focus on the logic layer. Rather than as before, designers put all the material in the hands of developers, who implement the interface. In the Eclipes tool, the development of Android in a more simple way, designers in the DroidDraw design interface, in XML storage, in the Eclipes directly open to see the designer interface.

The interface part of Android also uses the currently popular MVC framework, in Android:

1) View layer: The general use of XML file interface description, when used can be very convenient to introduce. Of course, how you learn more about Android, you can think of Android can also use javascript+html and other ways as the view layer, of course, there is a need for Java and JavaScript communication between, fortunately, Android provides a very convenient communication implementation between them.

2) control layer (Controller): The task of Android control layer usually falls on the shoulders of many acitvity, this phrase also implies do not write code in acitivity, to through activity delivery model business Logic layer processing, Another reason for this is that the response time of Acitivity in Android is 5s, and if time-consuming operations are put here, the program is easily recycled.

3) Model: the operation of the database, the operation of the network, etc. should be processed in the model, of course, business calculations and other operations must be placed in the layer. is the binary data in the application.


Data binding in the Android SDK also uses a similar approach to the MVC framework to display the data. Data binding is achieved by encapsulating the data in the control layer as required by the view model (that is, the adapter in the Android SDK) to be displayed directly on the view model. For example, the listactivity of all the data in the cursor, the view layer is a ListView, the data is encapsulated as ListAdapter, and passed to the ListView, the data is in the ListView reality.

MVC Architecture Design Reference

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.