mvc Principle and mvc Advantages and disadvantages of the model
mvc Principle and mvc Advantages and disadvantages of the model <https://www.cnblogs.com/lingyi/articles/3374429.html>
One ,mvc principle
mvc It is a kind of programming design mode , The display module is separated from the display module . It improves the maintainability of the program , Portability , Extensibility and reusability , The difficulty of program development is reduced . It is mainly divided into models , view , Controller layer 3 .
1, Model (model) It is the main part of the application , It mainly includes business logic module （web In the project Action,dao class ） And data module （pojo class ）. Model
Independent of data format , Such a model can provide data for multiple views . Because the code applied to the model only needs to be written once, it can be reused by multiple views , So it reduces the repeatability of the code
2, view (view) The interface with which users interact , stay web The middle view is generally composed of jsp,html form
3, controller (controller) Receiving requests from the interface And give it to the model for processing In this process, the controller does not do any processing, but acts as a connection
Two ,MVC The advantages of
1, Multiple views can be created and used at run time for a model . change - The propagation mechanism ensures that all relevant views get the model data changes in time , Thus, the behavior of all associated views and controllers can be synchronized .
2, Pluggability of view and controller , Allows replacement of view and controller objects , And it can be opened or closed dynamically according to the demand , Even object replacement occurs during runtime .
3, Model portability . Because the model is view independent , Therefore, a model can be transplanted to a new platform independently . All you need to do is make new changes to the views and controllers on the new platform .
4, Potential framework structure . The application framework can be built based on this model , It's not just used in the design of interface .
Three ,MVC The shortcomings of
1, It increases the complexity of system structure and implementation . For simple interfaces , Strictly follow MVC, Make the model , Separation of view from controller , It will increase the complexity of the structure , There may be too many update operations , Reduce operating efficiency .
2, Too tight connection between view and controller . The view and controller are separated from each other , But the parts that are really connected , The view does not have a controller , Its application is very limited , vice versa , This hinders their independent reuse .
3, Inefficient access of view to model data . According to the different model operation interface , Views may need to be called multiple times to get enough display data . Unnecessary frequent access to unchanging data , It will also impair operational performance .
4, at present , General advanced interface tools or constructors do not support patterns . Adapt these tools to MVC The cost of requiring and establishing separate components is high , This will result in MVC Difficulties in use .