Model-view-controller (MVC) is a software design model invented by XeroxPARC for programming language Smalltalk-80 in 1980s. it has been widely used. Sun's J2EE platform design model has been recommended in recent years and is receiving more and more
Model-view-controller (MVC) is a software design model invented by Xerox PARC for programming language Smalltalk-80 in 1980s. it has been widely used. Sun's J2EE platform design model has been recommended in recent years and is welcomed by more and more developers who use ColdFusion and PHP. Model-View-Controller mode is a useful toolbox, which has many benefits but also has some faults.
How MVC works
MVC is a design pattern that forces the input, processing, and output of an application. The application MVC is divided into three core components: Model, view, and controller. They process their own tasks.
View
A view is the interface on which the user sees and interacts with it. For older Web application, a view is an interface composed of HTML elements. in the new Web application, HTML still plays an important role in the view, however, some new techniques have emerged, including Macromedia Flash and Web services such as XHTML, XML/XSL, and WML.
How to deal with the use of the program interface has become increasingly provocative. One major benefit of MVC is that it can process many different views for your application. The view is not actually processed. whether the data is stored online or an employee list, it is just a method for outputting data and answering user control.
Model
The model represents enterprise data and business rules. Among the three components of MVC, the model has the most processing tasks. For example, it may use component objects such as EJBs and ColdFusion Components to process databases. The data returned by the model is neutral, that is, the model has nothing to do with the data pattern, so that a model can supply data to multiple views. Because model-based code can be reused by multiple views only once, code duplication is reduced.
Controller
The controller receives incoming data from users and calls models and views to meet user requirements. Therefore, when you click a hyperlink in the Web page and send an HTML form, the controller itself does not output anything or process anything. It only receives the request and decides which model component is called to process the request, and then determines which view is used to display the data returned by the model for processing.
Now, Let's summarize the processing process of MVC. the controller first receives the user's request and decides which model should be called for processing. then, the model uses the business logic to process the user's request and return data, finally, the controller uses the data returned by the corresponding View pattern model and presents it to the user through the presentation layer.
Why does MVC apply?
Most Web application programs are created using procedural languages such as ASP, PHP, and CFML. They mix the data-layer code such as the database query statement and the presentation-layer code such as HTML. Experienced developers will separate the data from the presentation layer, but this is usually not very easy. it requires careful planning and constant attempts. MVC basically forcibly removes them. Although structured MVC exploitation requires some additional work, the benefits it brings to us are unquestionable.