[ASP.]01-Understanding MVC pattern

Source: Internet
Author: User

asp
MVC Calf Road]01-Understanding MVC Patterns

Ps:mvc out for a long time, the work has not been a chance to use. Out of interest, I will begin to work on MVC in-depth study, through the blog record What I learned, and hope to get the treatise of you friends.

Directory of this document


Understanding the MVC pattern in the general sense

The MVC pattern (model-view-controller) is a software architecture model in software engineering, which divides the software system into the following three basic parts:

Model: models are used to encapsulate data that is relevant to the business logic of an application and how the data is processed. "Model" has the right to direct data access, such as access to the database. "Model" does not depend on "view" and "Controller", that is, the model does not care how it will be displayed or how it is manipulated.
View: Views enable the display of data for a purposeful purpose. There is generally no logic on the program in the view.
Controller: The controller acts as an organizational function between different levels to control the flow of the application. It handles the event and responds. An "event" includes the user's behavior and changes on the data model.

The above text is from Wikipedia. Based on the above text and my own understanding, I have drawn a diagram of the following aspects of the MVC relationship:

Note that different platforms and different language frameworks have different definitions of MVC and do not have a clear definition. In general, however, each part of the MVC pattern is clearly defined and clearly delineated. The logic for manipulating data exists only in the model, the logic that renders the data exists only in the view, and the requests and inputs that process the user exist only in the controller. This clear point-of-separation (separation of concerns) MVC pattern makes our applications easier to maintain and extend, regardless of the size of the application and the life cycle.

Understanding the Domain Model

Domain model is a visual representation of a conceptual class or a real-world object within a domain. Also called conceptual model, domain object model, business object model. It focuses on analyzing the problem areas themselves, discovering important business domain concepts, and establishing relationships between business domain concepts. A domain model is an object model that describes the implementation of a business use case, an abstraction of how business roles and business entities should be contacted and collaborated to perform business.

For MVC applications, the domain model is a very important part. Within an industry, we create models based on real-world entities, related operations, and rules. For C # programs, a domain model is a set of C # types (classes, structs, and so on) that encapsulate real-world objects, and some operations (or processing) of objects within a domain are methods that are defined in C # types, while some rules for manipulating objects within a domain are logical processes within a method, such as C # The Get and set methods of the property reader in the read-write class are controlled by the reading and writing members. As an example:

such as the banking sector, the individual "bank account" can be built into a model. Each account has a "bank card consumption" operation, which is a method under the bank account model. "No Overdraft" is a constraint on the use of a bank card for this account, which is defined as the logical processing within the bank card consumption method.

It's a little abstract, but it's easy to understand. And my understanding of the domain model can only be here, friends have a good experience of it. In short, in an MVC application, we need to have the concept of manipulating data by model, or adding an action, or adding or changing a rule to an action, which is changing the domain model of the application.

Understanding MVC in ASP.

The generalized ASP. NET MVC has the following features:

By dividing the project into model View and controller, this separation of tasks (also known as separation of concerns) makes complex projects easier to maintain, and test-driven components make applications easier to test.
A simple and extensible framework. The MVC framework is designed to make porting and customizing features easier. You can add your own view engine, URL rewrite policy, overloaded action method, and so on. MVC also supports Dependency injection (DI) and inversion of Control (IOC). A powerful URL rewriting mechanism makes it easier to build easy-to-understand and searchable URLs. The URL can contain no file name extensions, and you can rewrite the URLs to make them more friendly to search engines.
Support for existing ASP. ASP, you can use the existing page markup, user control, template page, data binding, and so on.
......

in ASP. NET MVC, the controller is usually the class that inherits the System.Web.Mvc.Controller. Each public method of a class in a controller is called an action method. Asp. NET routing system calls the corresponding action method based on the URL and routing configuration of the request, completing the operation of the domain model and then selecting a view to render to the client. Shows the relationship between controller, model, and view in ASP. NET MVC:

In addition, the ASP. NET MVC Framework can use any database, ORM framework, and other tools supported by.

For starters, I think that's pretty much the idea of ASP. If you want to better understand the concept of MVC in ASP. Recommended access to the MSDN documentation.

If you are a novice, to help you understand, it is recommended that you do a few simple demo, you can refer to another friend of the non-nonsense MVC Introductory Tutorial series blog.

The above is [ASP.]01-Understand the MVC pattern, more about topic.alibabacloud.com (www.php.cn)!

  • 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.