What is MVC?
Remember the first interview Phper (PHP is for me to quickly get started with another Web development language), people ask me mvc, I only know that M is Model,v is View,c is controller, specific to other knowledge I was ignorant, the result I was asked ask Sanbuzhi!! I didn't know how bad I was. So I decided not to make it clear! Find the following information
2006-12-17 12:02:37
Big Small
Model-View-Controller (MVC) is a software design pattern invented by Xerox PARC in the 80 's for programming language Smalltalk-80, which has been widely used so far. It has been recommended in recent years as a design model for the Sun's Java EE platform and is being welcomed by more and more developers using ColdFusion and PHP. Model-View-controller mode is a useful toolbox that has many benefits, but also has some drawbacks.
How MVC Works
MVC is a design pattern that makes it mandatory to separate the input, processing, and output of an application. Using an MVC application is divided into three core parts: model, view, controller. Each of them handles their own tasks.
View
A view is an interface that the user sees and interacts with. For older Web applications, views are an interface of HTML elements, and in modern Web applications, HTML still plays an important role in the view, but new technologies are emerging, including Macromedia Flash and Image xhtml,xml/xsl , WML, and some other identity languages and Web services.
How to handle an application's interface becomes increasingly challenging. One big benefit of MVC is that it can handle many different views of your application. There is really no real processing happening in the view, whether the data is stored online or an employee list, as a view, it is simply a way to output data and allow the user to manipulate it.
Model
Models represent enterprise data and business rules. Of the three parts of MVC, the model has the most processing tasks. For example, it may use artifact objects such as EJBS and ColdFusion to process the database. The data returned by the model is neutral, meaning that the model is independent of the data format, so that a model can provide data for multiple views. Because the code applied to the model can be reused by multiple views only once, it reduces the repetition of the code.
Controller
The controller accepts the user's input and invokes the model and view to complete the user's needs. So when you click a hyperlink in a Web page and send an HTML form, the controller itself does not output anything and do any processing. It simply receives the request and decides which model component is called to process the request, and then uses which view to display the data returned by the model processing.
Now we summarize the process of MVC, first the controller receives the user's request and decides which model should be called to process it, then the model uses the business logic to process the user's request and return the data, and finally the controller formats the data returned by the model with the corresponding view and renders it to the user through the presentation layer.
Why use MVC
Most Web applications are created in a procedural language like asp,php, or CFML. They mix data-tier code like database query statements with presentation layer code such as HTML. The more experienced developers separate the data from the presentation layer, but this is often not easy to do and requires careful planning and ongoing attempts. MVC is fundamentally mandatory to separate them. Although it takes some extra work to construct an MVC application, the benefits it brings to us are no doubt.
First of all, the most important thing is that multiple views can share a model, and as I mentioned, there are more and more ways to access your application now. One solution to this is to use MVC, whether your users want a flash interface or a WAP interface, and use a model to handle them. Since you have separated the data and business rules from the presentation layer, you can maximize the reuse of your code.
Since the data returned by the model is not formatted, the same artifacts can be used by different interfaces. For example, many of the data may be represented in HTML, but they may also be represented by Macromedia Flash and WAP. The model also has the capability of state management and data persistence processing, for example, session-based shopping carts and e-commerce processes can also be reused by flash sites or wireless networking applications.
Because the model is self-contained and detached from the controller and view, it is easy to change the data layer and business rules of your application. If you want to port your database from MySQL to Oracle, or change your RDBMS-based data source to LDAP, just change your model. Once you've implemented the model correctly, the view will display them correctly, regardless of whether your data comes from a database or an LDAP server. Since the three parts of an application using MVC are antagonistic, changing one does not affect the other two, so you can construct good loosely coupled components based on this design idea.
For me, the controller also provides the benefit of using a controller to join different models and views to complete the user's needs, so that the controller can provide a powerful means of constructing the application. Given some reusable models and views, the controller can select the model to process based on the user's needs, and then select the view to display the processing results to the user.
The drawbacks of MVC
The drawback of MVC is that it doesn't have a clear definition, so it's not easy to fully understand MVC. Using MVC requires careful planning, and because its internal principles are complex, it takes some time to think.
You will have to spend a considerable amount of time thinking about how to apply MVC to your application, and because of the strict separation of the model and view, this also has some difficulty in debugging the application. Each component needs to be thoroughly tested before it can be used. Once your artifacts have been tested, you can reuse them with no scruples.
In my personal experience, since we have divided an application into three parts, using MVC also means that you will be managing more files than ever before, which is obvious. It seems like our workload has increased, but remember that this is nothing compared to the benefits it can bring us.
MVC is not a good fit for small or medium-sized applications, and spending a lot of time applying MVC to applications that are not large in size will often outweigh the costs.
MVC is a great way to create software
The MVC design pattern is a good way to create software, and some of the principles it advocates, such as content and display, may be better understood. But if you want to isolate the artifacts of models, views, and controllers, you may need to rethink your application, especially the architectural aspects of your application. If you accept MVC and have the ability to cope with the extra work and complexity it brings, MVC will give your software a new level of robustness, code reuse, and structure.
Java Development Web application has several development approaches that conform to MVC design patterns.
1:jsp+servlet+javabean (EJB)
2:jsp+javabean (Controller) +javabean (EJB) (Model)
3:TDK (Turbine,velocity ...)
4:xsp
5:jsp+struts+javabean (EJB)
http://www.bkjia.com/PHPjc/318337.html www.bkjia.com true http://www.bkjia.com/PHPjc/318337.html techarticle What is MVC? Remember the first interview Phper (PHP is another web development language for me to get started quickly), people ask me mvc, I only know M is Model,v is View,c is controller, with ...