MVC is the abbreviation of model, view, controller. Android encourages weak coupling and component reuse, and the specific embodiment of MVC in Android is as follows:
model: is the subject part of the application, all the business logic should be in the layer (operation of the database, the network, etc. should be processed in the model, of course, the calculation and other operations must be placed on the layer).
View Layer: Is the part of the application that is responsible for generating the user interface. It is also the only layer that the user can see in the entire MVC architecture, receiving input from the user and displaying the user's processing results. The general use of XML file interface description, when used can be very convenient to introduce.
Control Layer (Controller): Controls the display of user interface data and the state of a new model object based on user input. The task of Android's control layer usually falls on the shoulders of many activities, which implies not to write too much code in activity, to deal with it through activity delivery model business logic processing layer, Another reason for this is that activity in Android has a response time of 5 seconds, and the program can easily be recycled if time-consuming operations are put here.
Here's a case for a brief introduction to the subcontracting layering in Android projects:
PackageCom.dy.mvctest.base;ImportAndroid.os.Bundle;ImportAndroid.support.v7.app.AppCompatActivity;/*** Created by Dy on 2016/5/9. */Public abstract classBaseactivityextendsappcompatactivity {@Override protected voidonCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (Setviewid ()); Findviews (); Init (); Initevents (); Loaddatas (); }/** * SetLayoutof ResourcesID * * @return */ protected Abstract intSetviewid(); /** * Find child controls */ protected abstract voidfindviews(); /** * Initialize */ protected abstract voidInit(); /** * setting up event snooping */ protected abstract voidinitevents(); /** * Loading Data */ protected abstract voidLoaddatas();}
PackageCom.dy.mvctest.base;ImportAndroid.os.Bundle;ImportAndroid.support.v4.app.Fragment;ImportAndroid.view.LayoutInflater;ImportAndroid.view.View;ImportAndroid.view.ViewGroup;/*** Created by Dy on 2016/5/9. */Public abstract classBasefragmentextendsFragment {@Override PublicViewOncreateview(Layoutinflater Inflater, ViewGroup container, Bundle savedinstancestate) {//Return Super.oncreateview (Inflater, container, savedinstancestate); View view = Inflater.inflate (Setviewid (), Container, False); Findviews (view); Init (); Initevent (); Loaddatas ();returnView; }/** * Set up ResourcesID * * @return */ protected Abstract intSetviewid(); /** * Find child controls */ protected abstract voidfindviews(View view); /** * Initialize */ protected abstract voidInit(); /** * setting up event snooping */ protected abstract voidinitevent(); /** * Loading Data */ protected abstract voidLoaddatas();}
Continue tomorrow ....
On the MVC pattern in Android