"Learn Swift from Scratch" study notes (Day67) - Cocoa Touch design pattern and application MVC pattern

Original article, welcome to reprint. Please indicate: Guan Dongsheng's blog 

The MVC ( Model-View-Controller , Model - View - Controller ) pattern is one of the fairly old design patterns that first appeared in the Smalltalk language. Now, many computer languages ​​and architectures have adopted the MVC pattern.

 

Overview of the MVC pattern

 

The MVC pattern is a composite design pattern consisting of the "Observer" ( Observer ) pattern, the "Strategy" pattern , and the " Composite " pattern. The MVC pattern consists of 3 parts, as shown in the figure, and the functions of these 3 parts are as follows.

 

  • model . Save the state of the application data, respond to the view's query on the state, process the application business logic, complete the function of the application, and notify the view of the state change.

  • view . Display information and provide an interface for the user. The user sends an action request to the controller through the view, and then sends an application to the model to query the state, and the change of the model state will be notified to the view.

  • controller . Receive user requests and update the model according to the request. Additionally, the controller updates the selected view in response to the user's request. The controller is the medium between the view and the model, which can reduce the coupling between the view and the model, make the rights and responsibilities of the view and the model clearer, and improve the development efficiency.

     

     

      

Corresponding to the "content" and "form" in philosophy, in the MVC model, the mode is "content", which stores the data required by the view, the view is the "form", the external presentation, and the controller is their medium. 

MVC pattern in Cocoa Touch

 

What we discussed above is the general MVC pattern, and the MVC pattern in the Cocoa and Cocoa Touch frameworks is slightly different from the traditional MVC pattern. The former's model and view cannot communicate at all, and all communication is done through the controller. as the picture shows.

 

 

       In the UIKit framework of the Cocoa Touch framework , UIViewController is the root class of all controllers, such as UITableViewController , UITabBarController , and UINavigationController . UIView is the root class for views and controls.

 

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327014279&siteId=291194637