Android Development-MVP Mode understanding

Source: Internet
Author: User

Before looking, forget all, step by step look on the line. Finally there will be a prototype demo, of course, the turn. Read the article, then look at the demo, and then look back at the article is very good understanding, it is best to write it again.

1.MVP Development mode can be understood as page interface programming, each layer of the skeleton is first through the establishment of interfaces, define each layer of the necessary methods, and then implement the method is completed.

2. In the MVP development model, each module code is divided into three layers, View,presenter,model layer.

3.view layer in the literal sense, is the view layer, in the MVP development model of Android, Activity,fragment, and other interface display as a view layer, in these visual layers, only do some view transformation operations, not data, logic operation.

3.1. Establish the interface: through the prototype setup, according to the layout interface will be changed, to write the corresponding interface method.

3.2. Implement the interface, in the corresponding interface method, complete the view transformation operation.

3.3. The view layer is only operated on views. Initializes the presenter layer interface implementation class object, and sends the object of the view layer interface implementation class to the past so that the presenter layer can operate on the view layer.

4.presenter layer, the control layer, in the presenter layer, holds the View,model layer interface implementation class object, is through these two layers implementation class object pair respectively to these two layers to operate.

4.1. Create an interface: two interfaces required

4.1.1: interface 1. According to the function of the view layer to implement, the corresponding interface method is written,

4.1.2: Interface 2. According to the model layer to callback back data, write the corresponding callback interface, and method.

4.2. Implement interface 1, 2, in the corresponding method, through the view layer implementation class object to the view layer operation, through the model layer to implement the class callback method, to obtain the business data

4.3. Through the above two, complete the view layer and the model layer decoupling and control.

5.model layer, is the data request, the operation of the layer, after processing, you can call the data through the callback to the presenter layer, the presenter layer through the holding of the interface of the view layer to implement some methods of the class object, the view layer to operate.

5.1. Establish interfaces to establish interface methods for business data requirements.

5.2. Implements the interface, completes the logical operation to the business data in the implementation class method, then passes the data to the presenter layer through the presenter interface callback method.

5.3. This layer only operates data and does not perform task operations on the view.

MVP Demo: a chestnut.

A good collection of MVP blog: A piece is enough.

Android Development-MVP Mode understanding

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.