. NET MVC and three-tier architecture

Source: Internet
Author: User

Although the two have been exposed for some time, but sometimes confuse the concept, here is not intended to explain the difference between them, because both are architectural patterns, and there is a certain degree of coexistence, in the actual development, the strict distinction is not very significant. Based on the recent knowledge involved in this part of the review, the programming process, the basic concept is more important, not technology.

Let's take a look at the three-tier architecture, the UI (presentation layer), the BLL (business Logic Layer), the DAL (data access Layer):

UI ( presentation layer ): mainly refers to the interface that interacts with the user . Used to receive data entered by the user and to display the data that the user needs after processing.

BLL: ( business logic layer ui Layer and dal

    DAL: ( data Access layer ): dealing with Databases . The main realization of the data increase, delete, change, check. Submits the data stored in the database to the business layer, while saving the data processed by the business layer to the database. (These operations are, of course, based on the UI layer.) The user's needs are reflected to the interface (UI), theUI is reflected to the BLL, the BLL is reflected to the dal, thedal is manipulated for data, One by one return after operation until the user's desired data is fed back to the user)

In fact, the real use of the three-layer architecture is aware that the three are through the entity to pass data, entity through three layers, the three connected together, but also to achieve the encapsulation of data entities, replacing the multi-variable data transfer between layers (data exchange), greatly simplifying the data exchange, It also reduces the probability of data errors. (Entity is actually the encapsulation of database table entities), the dependency between entity and layer three:

    

Then look at the MVC architecture, M (model models), V (view view), C (Controller controllers) three parts. In the MVC architecture, these three parts are necessary, but we can also be based on the actual needs of the project and the actual situation can be increased, such as the implementation of the service layer or the repository layer, we can expand themselves, greatly improving the flexibility of development.

Model (data Model): used to encapsulate data related to the business logic of the application, as well as the processing methods of its data operations (access operations of the database, i.e. additions and deletions, data structure definition; The model does not depend on the view and controller, which means that the model does not need to know how it will be displayed or how it is applied, but only to focus on the responsibilities that it has. The techniques common in model are the entity Framework (that is, EF), NHibernate, LINQ to SQL, Typed datasets, and ADO.

View: page display or get user input, view needs to be responsible for the data transmitted by the controller with "display logic" presented to the user, although the view needs Contorller to pass the data, but the view does not rely on a controller, As long as any controller can provide the data required by the view, the view can be displayed according to the display logic, which is a loosely related relationship.

Controller: The role of a result coordinator, because the m-v-c three parts are not directly connected, view cannot directly communicate with model, that is, model can manipulate data, view can display data, therefore, The data displayed by the view needs to be provided to the view by the controller when it is obtained from the model. That is, the controller's role lies between the user interface layer and the business logic layer.

Among them, the most important feature of MVC is that the separation of concerns and the Convention is better than the configuration. The separation of concerns, simply said to be "only pay attention to", this can be a good decoupling module, the complexity of each unit is relatively low, easier to develop, at the same time, but also enhance the maintainability of the program. The Convention is better than the configuration, in short, is the development process should abide by the Convention, such as: Controller's file name must end with a controller; View file must be placed in the Views folder The name of the view is the action name of the corresponding controller, and the Web API's action name should be preceded by an HTTP verb, and so on, which facilitates post-development and maintenance of the project so that no one else is willing to take over the project because of the flow of people.

. NET MVC and three-tier architecture

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.