MVC Design Mode (Model - View - Controller) Design Mode Introduction (ZZ)

xiaoxiao2021-03-06  80

1 Preface User Interface, especially graphical user interface, and assumes a role in displaying a problem model to a user and an interaction with the user. The user wants to keep the interaction interface relative stability, but more want to change and adjust the displayed content and form as needed. For example, it is required to support different interface standards or different display effects, adapt to different operational requirements. This requires the interface structure to support the adjustment of the interface to the interface without changing the functionality and model of the software. To do this, from the perspective of the interface, it is difficult to: how to make the software calculation model independently of the interface configuration while satisfying the interface requirements. Model - View - Control (MVC: Model-View-Controller) is a structural organization model of such an interactive interface. 2 MVC (Model-View-Control) MVC is proposed by Trygve Reenskaug, first applied in a SmallTalk-80 environment, making many interactions and interface systems, and Microsoft's MFC base classes also follow MVC ideas. For interface design variability, MVC is divided into models, views, and control three components of the interactive system. The model component is the problem logic handled by the software in an inner abstraction independent of the external display content and form, and the computational relationship of the core data, logic, and functionality of the problem is encapsulated. He is independent of the specific interface expression and I / O operation. View components show the information and specific forms of model data and logical relationships and status to the user. It obtains display information from the model, with multiple different display forms or views for the same information. The control component is to process the interaction of the user and the software. The responsibility is to control any changes in the model to ensure that the user interface is related to the corresponding connection between the model; it accepts the user's input, input feedback to the model, and then implement the model The calculation control is a component that coordinates the model and view. Typically a view has a controller. The model, the view is separated from the controller, so that a model can have multiple display elements. If the user changes the model's data through the controller of a view, all other views depending on these data should be reflected in these changes. Therefore, whenever data changes happen, the controller will notify all the views and cause the displayed updates. This is actually a change in model - communication mechanism. 2.1 Models, views, and control classes (1) models in MVC include the core data, logical relationships, and computing functions of the application problem. It encapsulates the required data and provides the operation procedure for completing the problem processing. The controller calls these operations based on the need for I / O. The model also provides a view to the view to provide an operation of accessing its data. This change-propagation mechanism reflects the registration relationship between each interdependent component. Model data and state changes will stimulate this change-propagation mechanism, which is a bond that is contacted between models, views, and controllers. (2) The view transfers the information to the user in the form of display. Different views express the data and status information of the model by different displays. Each view has an update operation that can be changed - the propagation mechanism is activated. When the update is called, the view obtains the data value from the model and uses them to update the display. At initialization, all views and models are established through the registration relationship with the change-propagation mechanism. A one-to-one relationship is maintained between the view and the controller, and each view creates a corresponding controller. The view is provided to the controller to process the displayed operation. Therefore, the controller can get the ability to actively excit the interface update. (3) The controller accepts the user's input by time triggering. How does the controller get an event dependent on an interface running platform. The controller processes the input event through the event processing process and provides the corresponding operational service for each input event, transforming the event into an excitation operation of the model or related view.

If the behavior of the controller relies on the state of the model, the controller should register in the change-propagation mechanism and provide an update operation. In this way, the behavior of the controller can be changed by a change in the model, such as disabling some operations. 3 MVC implementation 3.1 analysis application issues, separating the system, separating the system's kernel function, the control input of the function, three parts of the output behavior of the system. The design model component makes it packaged in kernel data and computing functions, providing an operation of accessing display data, providing an operation of controlling internal behavior, and other necessary operational interfaces. The data constitution and calculation relationship of the model class is formed. This part is closely related to the specific application problem. 3.2 Designing and implementing each view design of each view, which gets data from the model, display them on the screen. 3.3 Designing and implementing each controller For each view, specify the response time and behavior of the user operation. Under the influence of model status, the controller accepts and interprets these events using specific methods. The initialization of the controller establishes the connection with the model and the view, and start the event processing mechanism. The specific implementation method of the event processing mechanism relies on the interface of the interface. 3.4 Use the installed and uninstalled controller controller to have higher degrees of freedom and help to form a highly flexibility app. The separation of the controller and the view supports the flexibility combining the view and the different controller to achieve a different mode of operation, such as a read-only view to ordinary users, professional users, or not using the controller. This separation also provides a way for integrating new I / O devices in applications. 4 MVC changes to separate models, views, and controllers, making design and use great flexibility. However, in reality, the functions of the views and controllers are usually closely linked. The input event for controlling the view is usually related to the composition of the view. In a real-world design environment, interface operations and their processing are closely associated with interface forms. In this case, the view and controller are separated, and it is inconvenient to the analysis and design, and the operation is low. Therefore, the view and controller can be combined to design and implement. In the above implementation, you can generate a new view class as long as the views and controllers are combined. Thus, it is still maintained with the separation of the model, so the same model can still use multiple views. These views themselves have an event handling capacity and can still be controlled by the model. 5 MVC Advantages and Insufficient 5.1 Advantages of MVC MVC Before: (1) Multiple views can be established and used for one model at the same time. The change-propagation mechanism ensures that all related views get the model data change, so that all associated views and controllers make behavioral synchronization. (2) Connectivity of the view and the controller, allows replacement views and controller objects, and can be replaced or changed during operation based on demand dynamics. (3) Portability of the model. Because the model is independent of the view, you can transplant a model to a new platform work. It is only necessary to make new modifications on the new platform. (4) Potential frame structure. The application framework can be established based on this model, not just in the design interface. 5.2 Inadequateness of MVC The deficiencies of MVC are in the following aspects: (1) Increase the complexity of system structure and implementation. For simple interfaces, strictly follow the MVC, separate the model, view and controller, increase the complexity of the structure, and may generate too much update operation, reduce operational efficiency. (2) The view is too close to the controller.

转载请注明原文地址:https://www.9cbs.com/read-108549.html

New Post(0)