[Asp design] use the MVC model to guide your web design ideas-Version 2

Source: Internet
Author: User
Tags sql injection defense

We are used to process-based development and always look forward to object-oriented development. There is no internal force foundation. I read a lot of object-oriented books, but it is just a bit confusing. The concept of MVC is also occasionally known. I feel that it can be combined with web development to make projects object-oriented. Here is my experience.
First introduce the concept of MVC:
MVC (Model-View-Controller) separates the input, output, and processing processes of an application by model, view, and controller, such an application is divided into three layers: model layer, view layer, and control layer.
Model: Processes business processes/states and formulates business rules. It is the main core of MVC.
View: represents the user interaction interface, that is, the Web HTML interface.
Controller: it can be understood that a user receives a request from a user and matches the model with the view to complete the user's request.

The following uses a simple message board as an example.

1) from the above concept, the message board can be divided into three parts.
Model (m): contains database links, dataset generation, and database update operations.
View (V): contains the dataset for obtaining the model, which is filled in to various display interfaces, such as (message board list, management control page, add, modify, delete, and other pages displayed by users .)
Control (C): includes data verification for database updates. The updated results are forwarded to the view for presentation.

2) The three parts have been released. The following are further details.
Model (m)
Data Link: Process Data Link parameters and link failures.
Data Operations: Generate datasets in a fixed format, run a single SQL statement, and parse datasets in a fixed format to update the database (including message records, administrator accounts, and system settings ).
File Operation: the file format is encapsulated into a dataset with the read and write operations. (The content includes: Message board style setting, copyright setting, search engine keyword setting, and message board title setting)
View (V)
Data Display: Authorize the Controller [c] to request a dataset from the model [m] As required, and then display the interface based on the dataset.
Operation Result Display: The displayed prompt information is determined based on the data returned by the control.
Specific information includes:
Add message page: determines whether the message owner is an administrator and whether the message is replied or created.
Message Management page: Batch delete messages, query messages, Administrator account management, and system settings.
Message Display page: determines whether the message is dedicated to the Administrator, whether the message is published by the Administrator, whether the reply is allowed, whether the sensitive information of the message owner is displayed, and whether the message needs to be reviewed before display.

Control (C)
Data/file operations: receives operation data to check whether the data meets the conditions. reference the generated dataset class of the model to generate a specified dataset, and then hand it over to the corresponding model operation method for operation, obtain the operation result and forward it to the view for processing in a predefined format.

3) The system is basically refined. The next step is to encapsulate the above analysis into a class.
Model (m ):
Database links and data operations can be encapsulated into a class.
The structure of the database dataset, which can be completed by referencing the dictionary control and array. In this case, operations can also be encapsulated into a class, which can be used to simulate some mechanisms of dataset objects in Asp.net.
The file operation is encapsulated into a class.
The file structure definition can be encapsulated into a class to facilitate direct reference control, and then transferred to the file operation class for corresponding operations.
View (V ):
The view can all appear in file mode, or some code can be encapsulated and referenced. You can also reference the existing template class to implement code separation.
Control (c ):
Data Verification: SQL Injection defense, replacement of Japanese characters, and regular expressions for specific common verification. This is a common function of the controller. It can be encapsulated into a class or an independent file can exist in the function type, it is referenced directly during use.
Data/file update operations: Because of direct operations, you can avoid using class, instead of appearing in file mode, a class in each file processing model (m. And complete control (C.
View [v] model [c] linker: receives requests from a dataset from view [v] and converts requests to a model [m] suitable SQL statement, the model is then handed over to the [m] dataset generator to generate the dataset and then return it to the view [v]. This processing is troublesome. If you do not need to make it too rigorous, you can directly use the field name, in the [v] view, request data from the model [m] using SQL-standard conditional statements.

Suspect:
View [v] model [c] linker. I am still a little hesitant about this setting. In MVC, V does not require the blending of C in M requests. However, the operations of this linker are indeed in line with the concept of C, so here I put it in controller [C. Maybe it can be placed in the view [v. After all, this is about view [v. This depends on everyone's understanding of MVC.

The above has basically completed the structure analysis and class abstraction of the message board. There are a lot of things that are complicated, or even cool. It is not necessary for a message board to do this. However, in this example, many classes can be directly used in other larger projects, such as the dataset request converter in the controller [C, the validation section and the database links in the model [m] Follow the MVC model for programming, but in order to make the program design more flexible, the most important thing is that you can quickly split the project into a small block, and then fold the small blocks into smaller blocks, until they are folded to a certain attribute of a method of a single class, after you complete these small pieces of code, the system will complete.
In fact, this is already the second version. Thanks very much to the 5do8 [Old Farmer] in the Blue classic. After reading my first version, he chatted with me for less than 10 minutes and asked me to get to know MVC again, this guiding article is further improved. I am still exploring and may update this document. I hope it will be helpful to everyone.
If you have any ideas and suggestions on the above information, you can go to my blog to find me, the latest version of this article can go to (http://blog.csdn.net/oyiboy/archive/2006/02/09/595164.aspx) to view.

Gossip: Welcome to your friends with mobile phone to my "haiyu cell phone Gava station (http://wwww.fishjava.com)" to turn around, there are a lot of free mobile games and pictures to provide to you, you can not only play online trial games, download games and images directly through WAP, but also upload some fun games or pictures to play together.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.