MVC is a paradigm of design in interface development, and in mobile development
The full name of MVC is the Model View controller, which is the abbreviation for the models-view-controller.
It organizes code into a separate approach to business logic, data, and interfaces, and aggregates business logic into a single component, without the need to rewrite business logic while improving and customizing the interface and user interaction.
I've just been in touch with iOS and want to understand the MVC application in iOS with some example design for iOS.
1. iOS view
For the graphical interface design of the tool, this should be the design of the various view controls, the size, position, border, color (foreground, background), font, title and other properties of the page and control.
For a custom graphical interface, you still need code to design properties such as size, position, border, color (foreground, background), font, Titile, and so on for pages and controls.
UIView is one of the most basic classes in iOS view design. There are many attributes that need to be defined.
The data that is closely related to view is Viewcontroller, and the refresh and input submissions of the view are done through the controller.
Controller has control over view, simply speaking, a controller has the right to access its view entity.
What rights does a controller have? This is where the controller differs from the view, where the code separates.
2. Controller for iOS
Controller face view features are:
Can be displayed to modify the associated variable in view to drive the refresh of the view.
Can save the associated variables in the view to drive the model data updates on the server or cache.
To achieve a complete feature:
Controllers generally also have some features, such as:
1. Logic processing, data processing, error handling, etc.
2. Interacting with other controllers
3. Accessing the server
4. Accessing the database
From the above function, the controller can also be divided into several layers, such as the logical layer, the cache layer, the Server API call layer (such as rest).
3. Definition of the data structure used in iOS Modelcontroller. The definition of model is generally just the pojo pattern, which defines the getter, setter function of the member variable of an object. Or add some general data processing, such as Tojson, Fromjson, etc.
There is no business logic, it is a simple entity class.
This model is generally closely related to the Server protocol protocol and database tables.
Structure diagram of MVC
Some practical experience: 1. The protocol of the data model and the server should be separated. In general, the data model can share a set of structures with protocol. However, such coupling can be inconvenient, and changes in protocol frequently affect the data model, especially when variable names such as JSON and hibernate are associated with resources and strong relationships.
The data model can be chatty and protocol, but can be separated flexibly.
So, there can be a data model module, and a protocol module. When the protocol changes frequently, the old protocol can not be changed, and the data model can adapt to the new protocol and is compatible with the old protocol.
2. The evolution of the data model on the mobile side, the deletion of fields, the addition of all can, but it is best to remove easily confusing fields, repeating the meaning of the field. In the same data model, when different business respective fields, as far as possible to unify, can be the server side to maintain and compatible with the new and old protocol.
3. The protocol of each REST API call is minimized, easy to transfer, function separated, etc., and maintained for scalability. For minimization, empty objects are null, an empty array [] is filtered during transport, and for protocol try not to use existing nested objects as much as possible, this can be confusing and there are many deep nesting and blank fields.
For extensibility, such as adding {} Nesting, it is easy to extend new objects.
MVC patterns and hierarchies in mobile development