Android's MVC mode

        MVC (Model-View-Controller): M refers to the logical model, V refers to the view model, and C refers to the controller. A logical model can be used for multiple view models. For example, a batch of statistical data can be represented by a bar chart or a pie chart. One view model can also be used for multiple logical models. The purpose of using MVC is to separate the implementation codes of M and V, so that the same program can use different forms of expression, and the purpose of C is to ensure the synchronization of M and V. Once M changes, V should be updated synchronously. This It is exactly the same as the observer mode in "Design Patterns".

      MVC benefits: From the user's point of view, users can choose their own suitable way of browsing data according to their needs. For example, for an online document, the user can choose to read it as an HTML page or as a pdf. From the developer's point of view, MVC completely separates the application logic layer from the interface. The biggest advantage is that interface designers can directly participate in interface development, and programmers can focus on the logic layer. Rather than as before, designers hand over all materials to developers, who will implement the interface. A simpler method is used to develop Android in the Eclipes tool. The designer designs the interface in DroidDraw, saves it in XML, and opens it directly in Eclipes to see the interface designed by the designer. 

       The interface part of Android also uses the currently popular MVC framework. In Android: 

 

  1) View layer (View): Generally, an XML file is used to describe the interface, which can be easily introduced when using it. Of course, if you know more about Android, you can definitely think of using JavaScript+HTML as the View layer in Android. Of course, communication between Java and JavaScript is needed here. Fortunately, Android provides a very convenient communication between them.     

  2) Control layer (Controller): The important task of Android's control layer usually falls on the shoulders of many Acitvity. This sentence also implies that you should not write code in Acitivity, but must be handled by the Activity delivery model business logic layer. Another reason for doing this is that the response time of Acitivity in Android is 5s. If the time-consuming operation is placed here, the program is easily recycled.

  3) Model layer (Model): The operation of the database, the operation of the network, etc. should be processed in the Model, of course, the operation of business calculation must also be placed in this layer. It is the binary data in the application.


      The data binding in the Android SDK also uses a method similar to the MVC framework to display data. In the control layer, the data can be directly displayed on the view model by encapsulating the data according to the requirements of the view model (that is, the Adapter in the Android SDK), thereby realizing data binding. For example, in the ListActivity that displays all the data in the Cursor, its view layer is a ListView. The data is encapsulated as a ListAdapter and passed to the ListView, and the data is displayed in the ListView.

Guess you like

Origin blog.csdn.net/dongyu1009/article/details/9848781