The MVC mode may be the most classic design pattern in software design. The model view controller of the Smaltalk class library touches the inspiration, clear hierarchy of software design, clear responsibilities, smooth workflow to make software design Added an artistic beauty.
MVC mode itself - Simple from literal and application Some developers work and reduce future maintenance costs. (If you are familiar with the Model 2 mode developed by JSP, it can be found that it is also a very good manifestation of the MVC mode.).
Model: Maintain data and provide data access methods.
View: Partial data or all data of the model.
Controller: Handling events.
Introducing the MVC mode on the one hand, the overall design of the system, is pointed out in the clear direction, and is also a good guidance for the division of labor of the development team.
Since the overall structure of the system is logically divided into three parts in accordance with the MVC mode, the developers of the team also have developers for each part.
The following is a typical MVC communication method
The event is processed by the controller, the controller receives the user event, and the model is changed according to the type of event.
The view will be registered in the model in advance. Each view that has been registered to this model immediately is notified when the model data changes.
The view acquires the latest data from the mold and refreshes yourself.
To implement MVC, the most important part is the Observer mode in Design Pattern. The OBServer mode allows an object to notify multiple observer (Observer) when modifying the observed object.
MVC design model
Disadvantages of MVC
The design implementation of MVC is not very easy, and it is relatively easy to understand, but it is relatively high for developers. MVC is just a basic design idea and requires detailed design planning.
The stringent separation of models and views may make it difficult to debug, but it is easier to find errors.
Experience shows that MVC is divided into three layers, meaning that the code file is increased, so for the management of the documentation needs.