The problem of view decoupling in mobile app development

Source: Internet
Author: User

These days in the iOS code to do the decoupling of things, by the way a few words in the development of the view decoupling problem.
First, let's first position the view role: View should only worry about the front/back color, font properties, layout features, X/y/width/height and other pure visual properties. You should not worry about data loading, modification, incident response, etc. model and controller concerns. Of course, it also includes a custom view.


Next, we discuss how to reduce the impact of the view partial coupling on the overall architecture in the actual development of this role.
1, the View initialization, property settings should have their own owner, should not be placed in the controller. Of course, this job may be replaced by an XML layout in Android or Xib in iOS. Controller is only responsible for getting the reference to the view to do the following settings default data, installation listener and so on.
2, data provision and update refresh, should be triggered by the controller, if the data is more complex, such as lists, Gongge, etc., should be added adapter layer to do model and view decoupling.
3, the event trigger should be through the listener to achieve the decoupling of the view and controller, do not put the logic of the event corresponding directly to the view, which will affect the reuse of the view, making the code difficult to maintain.
4, the screen to adapt the problem in the view internal resolution, do not do in the controller. For example, there is a flexible layout in the XML in Android, or the use of AutoLayout in iOS.


Finally, let's take a look at the actual operation.
The XML layout provided in Android is actually forced decoupling, which makes it very rare to mix other code in the view when we use it, and we just need to be aware that when the model of the view is more complex, the adapter layer is added to decouple it.
The code generation View, which is commonly used for historical reasons in iOS, causes the view to be generated in the controller, the View property set, and the MVC coupling that implements the functional logic in view is more serious. Given that storyboard has more restrictions on controllers, it is recommended to provide a view layout via Xib in a large iOS project, referring to Android, and to map the view instance through Iboutlet to the controller. Load the data through the controller and install the listener. Do not appear in the controller to manipulate the visual properties of view Code.

The problem of view decoupling in mobile app development

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.