Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does the mvc framework mean?

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces what the mvc framework refers to, has a certain reference value, friends in need can refer to. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

The mvc framework is a design pattern that forcibly separates the input, processing, and output of an application, so that the same program can use different forms of expression.

MVC (Model View Controler) originally exists in the Desktop program. M refers to the data model, V refers to the user interface, and C is the controller. The purpose of using MVC is to separate the implementation code of M and V so that the same program can use different representations. For example, a batch of statistics can be represented by bar charts and pie charts respectively. The purpose of C is to ensure the synchronization of M and V. once M changes, V should be updated synchronously.

Model-View-Controller (MVC) is a software design pattern invented by Xerox PARC for the programming language Smalltalk-80 in the 1980s, and it has been widely used. In recent years, it has been recommended as the design pattern of Sun's J2EE platform, and is welcomed by more and more developers who use ColdFusion and PHP. The Model-View-Controller pattern is a useful toolbox that has many advantages but also some disadvantages.

How MVC works

MVC is a design pattern that forcibly separates the input, processing, and output of the application. Using MVC applications is divided into three core components: model, view, and controller. They each handle their own tasks.

View

A view is an interface that the user sees and interacts with. For the old Web application, the view is the interface composed of HTML elements. In the new Web application, HTML still plays an important role in the view, but some new technologies have emerged one after another, including Macromedia Flash and some markup languages such as XHTML,XML/XSL,WML and Web services.

How to deal with the interface of an application is becoming more and more challenging. A big benefit of MVC is that it can handle many different views for your application. No real processing occurs in the view, whether the data is stored online or a list of employees, as a view, it is just a way to output data and allow users to manipulate it.

Model

The model represents enterprise data and business rules. Of the three parts of MVC, the model has the most processing tasks. For example, it might use component objects such as EJBs and ColdFusion Components to process the database. The data returned by the model is neutral, that is, 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, the repeatability of the code is reduced.

Controller

The controller accepts the user's input and invokes the model and view to complete the user's requirements. So when you click the hyperlink in the Web page and send the HTML form, the controller itself doesn't output anything or do any processing. It simply receives the request and decides which model artifact to call to process the request, and then uses to determine which view to use 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 to call for processing, then the model processes the user's request and returns data with business logic, and finally the controller formats the data returned by the model with the corresponding view and presents it to the user through the presentation layer.

Why use MVC

Most Web applications are created in procedural languages like ASP,PHP or CFML. They mix data-tier code such as database query statements with presentation-tier code such as HTML.

More experienced developers will separate the data from the presentation layer, but this is usually not easy to do and requires careful planning and constant experimentation. MVC fundamentally forcefully separates them. Although building MVC applications requires some extra work, there is no doubt about the benefits it brings to us.

First of all, the most important point is that multiple views can share a model, and as I mentioned, there are more and more ways to access your application. One solution to this is to use MVC, whether your users want a Flash interface or a WAP interface; you can deal with them with a model. Because you have separated data from business rules from the presentation layer, you can maximize the reuse of your code.

Because the data returned by the model is not formatted, the same component can be used by different interfaces. For example, a lot of data may be represented in HTML, but they may also be represented in Macromedia Flash and WAP. The model also has the functions of state management and data persistence. For example, session-based shopping carts and e-commerce processes can also be reused by Flash sites or wireless applications.

Because the model is self-contained and separate 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 have implemented the model correctly, the view will display it correctly, whether your data comes from a database or a LDAP server. Because the three parts of an application using MVC are opposed to each other, changing one of them will not affect the other two, so according to this design idea, you can construct good loosely coupled components.

For me, the controller also provides an advantage, which is that the controller can be used to join different models and views to meet the needs of users, so that the controller can provide a powerful means for constructing applications. Given some reusable models and views, the controller can select the model to process according to the needs of the user, and then select the view to display the processing results to the user.

Shortcomings of MVC

The disadvantage of MVC is that because it is not clearly defined, it is not easy to fully understand MVC. Using MVC requires careful planning, and because its internal principles are complex, it takes some time to think about it.

You will have to spend considerable time thinking about how to apply MVC to your application, and it will be difficult to debug the application because of the strict separation of models and views. Each component needs to be thoroughly tested before it is used. Once your components have been tested, you can reuse them without scruples.

In my personal experience, since we have divided an application into three parts, it is obvious that using MVC also means you have to manage more files than ever before. It seems that our workload has increased, but please remember that it is nothing compared to the benefits it can bring us.

MVC is not suitable for small or even medium-sized applications, and spending a lot of time applying MVC to applications that are not very large often outweighs the gain.

MVC is a good way to create software.

The MVC design pattern is a good way to create software, and some of the principles it advocates, such as the separation of content and display, may be easier to understand. But if you want to isolate the components of the model, view, and controller, you may need to rethink your application, especially the architectural aspects of the application. If you accept MVC and have the ability to cope with the extra work and complexity it brings, MVC will take your software to a new level in terms of robustness, code reuse, and structure.

Thank you for reading this article carefully. I hope the editor can share what the mvc framework refers to is helpful to everyone. At the same time, I also hope you can support us, pay attention to the industry information channel, and find out if you have any problems. Detailed solutions are waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report