MVC (In-depth Study)

Source: Internet
Author: User
Tags ldap ruby on rails

MVC(Model-View-controller, Model-View-controller mode) is a software architecture mode in software engineering. It divides a software system into three basic parts: model, view, and controller ).

MVC was first established by Trygve reenskaug in 1974[1] It was proposed that Xerox PARC wasProgramA Software Design Model invented by the Language smalltalk.Model-View-controller modeThe purpose is to implement a dynamic program design, simplify subsequent modifications and extensions of the program, and make reuse of a part of the program possible. In addition, this mode simplifies the complexity to make the program structure more intuitive. The software system also gives the functions of each basic part through the separation of its basic parts. Professionals can use their own expertise groups:

    • Controller-forwards requests and processes the requests.
    • View-graphic interface design by the interface designer.
    • Model-functions (implementedAlgorithmDatabase experts perform data management and database design (specific functions can be implemented ).

Directory

[Hide]

  • 1 Level
  • 2 Advantages
  • 3 Disadvantages and Applicability
  • 4 Implementation
    • 4.1 MFC
    • 4.2 Java
      • 4.2.1 JAVA Platform Enterprise Edition (J2EE)
      • 4.2.2 Java swing
    • 4.3 . Net
      • 4.3.1 ASP. NET
      • 4.3.2 ASP. NET MVC
      • 4.3.3 Windows Forms
    • 4.4 Perl
    • 4.5 Ruby on Rails
    • 4.6 Python
    • 4.7 Javascript
    • 4.8 PHP
    • 4.9 ActionScript 3
  • 5 References
  • 6 External link


[Edit] Level

Model)The data model is used to encapsulate data related to the application's business logic and to process the data. "Model" has the right to access data directly, such as accessing a database. "Model" does not depend on "View" and "controller", that is, the model does not care about how it is displayed or operated. However, data changes in the model are generally published through a refresh mechanism. To implement this mechanism, the views used to monitor this model must be registered on this model in advance, so that the views can understand the changes in the data model. (Comparison: Observer mode (software design mode ))

View)The view layer can display data purposefully (theoretically, this is not necessary ). Generally, there is no program logic in the view. To refresh a view, the view needs to access the data model it monitors. Therefore, you should register the data that it monitors in advance.

Controller)The Controller acts as an organizational unit between different layers and is used to control application processes. It processes events and responds. "Events" include user behaviors and changes in data models.

[Edit] Advantages

In the initial JSP page, data layers such as database query statementsCodeMixed with the presentation layer code like HTML. Experienced developers will separate the data from the presentation layer, but this is usually not easy. It requires careful planning and continuous attempts. MVC strictly separates them. Although constructing an MVC application requires some additional work, the benefits it brings us are beyond doubt.

First, multiple views can share one model. Today, the same web application provides a variety of user interfaces. For example, you want to be able to send and receive emails through a browser, or access your email through a mobile phone, this requires the web site to provide both the Internet interface and WAP interface. In the MVC design mode, the model responds to user requests and returns response data. The view is responsible for formatting and presenting the data to the user. The business logic is separated from the presentation layer, the same model can be reused by different views, which greatly improves code reusability.

Second, the model is self-contained and is relatively independent from the Controller and view, so you can easily change the data layer and business rules of the application. If you port a database from MySQL to Oracle or change the RDBMS data source to an LDAP data source, you only need to change the model. Once the model is correctly implemented, the view correctly displays the data from the database or the LDAP server. Because the three modules of MVC are independent of each other, changing one of them will not affect the other two. Therefore, based on this design idea, a well-formed component with loose coupling can be constructed.

In addition, the Controller improves application flexibility and configurability. Controllers can be used to connect different models and views to meet user needs. They can also build applications to provide powerful means. Given some reusable models and views, the controller can select an appropriate model for processing based on the user's needs, and then select an appropriate view to display the processing results to the user.

[Edit] Disadvantages and Applicability

The disadvantage of MVC is that it is not easy to fully understand MVC because it is not clearly defined. Using MVC requires careful planning. Because of its complicated internal principles, it takes some time to think about it. Developing an MVC Architecture Project will have to spend considerable time thinking about how to apply MVC to applications. At the same time, due to the strict separation of models and views, this also makes it difficult to debug the application. Each component must be thoroughly tested before use. In addition, because MVC divides an application into three parts, this means that the same project will contain more files than before.

Therefore, MVC is not suitable for small or medium-sized applications, which will bring additional workload and increase application complexity. However, for large-scale applications with a large number of user interfaces and complex logic, MVC will bring a new step to the software in terms of robustness, code reuse, and structure. Although the initial construction of the MVC Framework requires a certain amount of work, it will greatly improve the efficiency of software development in the long run.

[Edit] Implementation [Edit] MFC

Microsoft's MFC Document/view architecture was an early implementation of MVC. MFC divided the program into two categories: cview and cdocument. The document corresponds to the Model in MVC, view is equivalent to view + controller in MVC, and added the cwinapp class to synthesize three items. However, MFC is basically a failed MVC file.

Because the document/view definitions under MFC are too vague and the controller (messagemap) is not taken out, the controller can be placed in the view or document, But no matter which aspect is placed, will be bound to the view or document, with no flexibility.

[Edit] Java [Edit] JAVA Platform Enterprise Edition (J2EE)

Unlike other frameworks, J2EE defines a specification for Model objects.

View)
In J2EE applications, views may be undertaken by Java Server Page (JSP. The code for generating a view may be part of a servlet, especially when the client server interacts.
Controller)
In J2EE applications, the Controller may be a servlet, which is usually implemented using struts.
Model)
The model is implemented by an entity bean.
[Edit] Java swing [Edit] . Net [Edit] ASP. NET

In ASP. NET, views and controllers are not well defined. The model is left for developers to design.

View)
The aspx and ascx files are used to process the view's responsibilities. In this design, the view is actually inherited from the Controller. This is different from the implementation of smalltalk. In smalltalk, different classes have pointers pointing to each other.
Controller)
The responsibilities of the controller are divided into two parts. The generation and transmission of events are part of the Framework. More specifically, there are two classes: page and control. Event processing is implemented in the separated code.
Model)
ASP. NET does not require a model strictly. Developers can create a model class on their own, However, many people choose to give up this step and put event processing in the Controller to process any computing.And data storage. However, it is feasible to use models to include business logic and data access.
[Edit] ASP. NET MVC

Aiming at the shortcomings of ASP. NET in MVC Architecture support, ASP. net mvc is expected to be launched in ASP. NET 4.0.

[Edit] Windows Forms

In winforms, the view and controller modes have been well defined. The model is left for developers to design.

View)
The role of a class that is inherited by the form or control class to process the view. In the winform example, the image and controller are compiled in the same class, which is different from ASP. NET.
Controller)
The responsibilities of the controller are divided into three parts. Event generation and transmission are part of the operating system. In the. NET Framework, the form and control classes forward different events to corresponding event processors. Event processing is implemented in the separated code.
Model)
Like ASP. NET, winform does not require a model strictly. Developers can create a model class on their own, but many choose to abandon this step and put event processing in the Controller to process any computing and data storage. That is to say, the model is used to include business logic and data access.
[Edit] Perl

Catalyst and jifty are Web frameworks developed using the Perl language and both adopt the Model-View-controller architecture. The catalyst itself only implements the controller. View and model allow developers to freely select the module development on CPAN. For example, both template and template declare can be used to generate views. Jifty implements MVC completely. In earlier versions, the view is implemented using Mason, and in later versions, the template declare is used.

[Edit] Ruby on Rails

Ruby on Rails is a Web framework developed in the ruby language and adopts the Model-View-controller architecture. The model part uses the active record concept and the migration mechanism to make the model structure very easy to control.

[Edit] Python

Python has many MVC architectures. The most common tools are Django and turbogears.

[Edit] Javascript
    • Model-View-controller (MVC) with JavaScript
[Edit] PHP
    • The Model View Controller framework for PHP Web Applications
[Edit] ActionScript 3
    • Puremvc standard for ActionScript 3
[Edit] References
    1. ^Trygve M. H. reenskaug/MVC-XEROX Parc 1978-79
[Edit] External link
  • An overview of the MVC pattern in Java from the sun website
  • Model View presenter with ASP. NET codeproject article.
  • History of the evolution of MVC and Derivatives by Martin Fowler.
  • ASP. net mvc Framework Microsoft's Scott Guthrie on. NET MVC
  • Introduction to the ASP. NET Model View Controller (MVC) Framework Scott hanselman builds an application step-by-step using the first CTP of the ASP. net mvc framework in this introductory video
  • Holub, Allen. Building user interfaces for object-oriented systems, Java World. 
  • Greer, Derek. "interactive application architecture patterns", Ctrl-shift-B, 2007.
  • Building graphical user interfaces with the MVC pattern in Java
  • What is behind MVC

newpp limit Report
Preprocessor node count: 3782/1000000
post-expand include size: 139299/2048000 bytes
template argument size: 19111/2048000 bytes
expensive parser function count: 10/500
--> from "http://zh.wikipedia.org/zh-cn/mvc"

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.