The MVC pattern (model-view-controller) is a software architecture model in software engineering, which divides the software system into three basic parts: model, view and controller.
The MVC pattern was first proposed by Trygve Reenskaug in 1978 [1] and was a software design model invented by Xerox PARC in the 1980s for programming language Smalltalk (Palo Alto). The purpose of the MVC pattern is to implement a dynamic program design that simplifies the subsequent modification and expansion of the program, and makes it possible to reuse a part of the program. In addition, this mode makes the program structure more intuitive by simplifying the complexity. The software system is separated by the basic parts of itself and also gives the functions of the basic parts. Professionals can be grouped by their own expertise:
- (Controller controllers)-responsible for forwarding requests and processing requests.
- (views view)-graphical interface design for interface designers.
- (model)-Programmer to write the functions that the program should have (implementation algorithm, etc.), database experts for data Management and database design (can achieve specific functions).
MVC pattern
Directory[Hide]
- 1 Interaction of components
- 2 Advantages
- 3 Evaluation and scope of application
- 4 Implementation
- 4.1 MFC
- 4.2 Java
- 4.2.1 Java Platform Enterprise Edition (EE)
- 4.2.2 Java Swing
- 4.3 Android
- 4.4 . NET
- 4.4.1 ASP .
- 4.4.2 ASP . NET MVC
- 4.4.3 Windows Forms
- 4.5 Perl
- 4.6 Ruby on Rails
- 4.7 Python
- 4.8 JavaScript
- 4.9 PHP
- 4.10 ActionScript 3
- 5 References
- 6 External Links
component Interaction [edit ] Typical collaboration between MVC components
In addition to dividing the application into three components, the model-view-controller (MVC) design defines the interaction between them. [2]
- model is 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. However, changes in the data in the model are generally advertised through a refresh mechanism. To implement this mechanism, the views that are used to monitor this model must be registered in advance on this model, so that the view can understand the changes that have occurred on the data model. (Comparison: Viewer mode (software design mode))
- views enable the purposeful display of data (in theory, this is not required). There is generally no logic on the program in the view. To implement the Refresh feature on the view, the view needs to access the data model it monitors, so it should be registered with the data it is monitoring beforehand.
- 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.
Benefits [Edit ]
In the original JSP Web page, the data-tier code such as the database query statement (SQL query) and the presentation layer code like HTML are mixed together. While a well-experienced developer separates data from the presentation layer, such a good design is often not easy to achieve, and it requires careful planning and ongoing attempts. MVC can be fundamentally forced to separate them. Although it takes some extra work to construct an MVC application, the benefits it brings to us are beyond doubt.
First, multiple views can share a model. Today, the same Web application provides a variety of user interfaces, such as the ability to send and receive e-mail through a browser, and to access the email via a mobile phone, which requires the Web site to provide both an Internet interface and a WAP interface. In MVC design mode, the model responds to user requests and returns response data, the view is responsible for formatting the data and presenting them to the user, business logic and presentation layer separation, the same model can be reused by different views, so greatly improve the reusability of the code.
Second, the controller is self-contained (self-contained) refers to the High independent cohesion of the object, and the model and view remain relatively independent, so it is convenient to change the application data layer and business rules. For example, porting a database from MySQL to Oracle, or transforming an RDBMS data source into an LDAP data source, simply change the model. Once the controller is implemented correctly, the view displays them correctly, regardless of whether the data is from the database or the LDAP server. Since the three modules of the MVC pattern are independent of each other, changing one of them will not affect the other two, so it is possible to construct a good number of less-intrusive components based on this design idea.
In addition, the controller improves the flexibility and configuration of the application. Controllers can be used to connect different models and views to complete the user's needs, or to construct applications that provide a powerful tool. Given some reusable models and views, the controller can select the appropriate model to process according to the user's needs, and then select the appropriate view to display the processing results to the user.
evaluation and scope of application [edit ]
The downside of the MVC pattern is that it doesn't have a clear definition, so it's not easy to fully understand the MVC pattern. Using the MVC pattern requires careful planning, and because of its complex internal principles, it takes some time to think. The project of developing an MVC schema architecture will have to spend considerable time thinking about how to apply the MVC pattern to the application, as well as the strict separation of the model and view, which also poses some difficulties for debugging the application. Each component needs to be thoroughly tested before it can be used. In addition, because the MVC pattern divides an application into three parts, this means that the same project will contain more files than before.
In the past, the MVC pattern was not suitable for small or even medium-sized applications, which resulted in additional workload and increased application complexity. But now most software design frameworks can provide an MVC skeleton directly and quickly for small and medium-sized applications to develop, and this problem no longer exists. For large applications that have a large number of user interfaces and are logically complex, MVC will give the software a new level of robustness, code reuse, and structure. Although it will take a certain amount of effort to initially build the MVC Schema framework, it will greatly improve the efficiency of later software development in the long run.
implementation [edit ] MFC[edit ]
The MFC Document/view architecture introduced by Microsoft is an early implementation of the MVC pattern, and MFC divides the program into CView and CDocument, where the Document corresponds to the model in MVC, The view is equivalent to the View+controller in MVC, plus the CWinApp class, which synthesizes three major items. But basically MFC is a failure of the MVC pattern works.
Because the Document/view definition under MFC is too vague to remove the controller (MESSAGEMAP) part, the controller can place the view or document, but regardless of which aspect it is placed in, Will be tied to view or document, with no elasticity.
Java[edit ] Java Platform Enterprise Edition (EE)[edit ]
Unlike many other frameworks, the Java EE defines a specification for model Objects.
-
Views (view)
In the
-
Java EE application, the view may be assumed by the SQL Server Page (JSP). The code that generates the view may be part of a servlet, especially when the client server interacts.
-
Controllers (Controller)
-
in a Java EE application, the controller may be a servlet and is now generally implemented with the struts2/spring framework.
-
Models (model)
-
the model is implemented by an entity bean.
Java Swing[edit ]
Swing is a standard MVC structure. Componentui represents view, which is responsible for drawing components. Components are especially model layers, such as JTextField document, JTable TableModel, JTree TreeModel, and so on. While control may not be obvious, we may simply consider its event mechanism as a controller developed by the swing team to developers.
As a Java developer, learning to swing is really a good choice if you want to understand the structure of MVC.
Android[edit ]
The interface part of Android also uses the currently popular MVC framework, in Android:
-
Views (view)
The
-
general use of XML file interface description, when used can be very convenient to introduce. Of course, how you learn more about Android, you can think of Android can also use javascript+html and other ways as the view layer, of course, there is a need for Java and JavaScript communication between, fortunately, Android provides a very convenient communication implementation between them.
-
Controllers (Controller)
The
-
task of Android's control layer usually falls on the shoulders of many activities, which implies not to write code in activity, to be processed by activity delivery model business logic layer, Another reason for this is that the response time of activity in Android is 5s, and if time-consuming operations are put here, the program is easily recycled.
-
Models (model)
The operation of the database, the operation of the
-
network, etc. should be processed in the model, of course, business computing and other operations must be placed in the layer. is the binary data in the application.
. NET[Edit ] asp[edit ]
In ASP., the schema for views and controllers (Controller) is not well defined. The model is left to developers to design.
-
Views (view)
-
aspx and ascx files are used to handle the responsibilities of the view. In this design, the view is actually inherited from the controller. This differs from the Smalltalk implementation in that different classes in Smalltalk have pointers pointing to each other.
-
Controller (Controllers)
-
the responsibilities of the controller are partitioned into two parts. The generation and transmission of events is part of the framework, and more specifically, the page and control two classes. The handling of events is implemented in separate code.
-
Models (model)
-
a model is not strictly required for ASP. Developers can choose to create a model class themselves, but many people choose to abandon this step, directly put the event processing in the controller to handle any calculations, data preservation and so on. But using models to contain business logic and data access is achievable.
asp[edit ]
- ASP. NET MVC, stable version on October 17, 2013 to version 5.0. [3]
In addition, in ASP. NET MVC, the model is typically paired with the LINQ to SQL Class (the dbml file created using the O/R Designer Tool) or the ADO. NET Entity Data model, using the ADO An edmx file created by the Entity framework) to implement.
Windows Forms[edit ]
In WinForms, this pattern for views and controllers (Controller) is well defined. The model is left to developers to design.
-
Views (view)
-
A class that inherits from a form or control class handles the view's responsibilities. In the WinForm example, the view and controller are compiled in the same class, which differs from ASP.
-
Controllers (Controller)
-
the responsibilities of the controller are partitioned into three parts. The generation and transmission of events is part of the operating system. In the. NET Framework, the form and control classes forward different events to the appropriate event handlers. The handling of events is implemented in separate code.
-
Models (model)
-
just like ASP. WinForm, a model is not strictly required. Developers can choose to create a model class themselves, but many people choose to abandon this step, directly put the event processing in the controller to handle any calculations, data preservation and so on. This means that the model is used to include business logic and data access.
Perl[edit ]
Catalyst and Jifty are web frameworks developed through the Perl language, all using the Model-view-controller architecture. Catalyst itself only made Controller,view and Model to allow developers to freely choose CPAN on the development of modules, such as template and template Declare can be used to generate views. Jifty the full implementation of MVC, part of the View was done in earlier versions using Mason, and the newer version uses Template Declare.
Ruby on Rails[edit ]
Ruby on Rails is a WEB framework developed through the Ruby language, and also uses the Model-view-controller architecture. The model section uses the Active Record concept to do the work, plus the migration mechanism, making its model structure very easy to control.
Python[edit ]
Python has a number of MVC architectures. The most commonly used are Django and turbogears.
JavaScript[edit ]
- Backbone.js
- Angular.js
- Ember.js
- Javascriptmvc
- Model-view-controller (MVC) with JavaScript
PHP[edit ]
- Cakephp
- CodeIgniter
- Prado
- Symfony
- Yii Framework
- Zend Framework
- Phalcon
ActionScript 3[edit ]
- PureMVC Standard for ActionScript 3
references [edit ]
- ^ Reenskaug, Trygve. Thing-model-view-editor:an Example from a planningsystem.
- ^ Buschmann, Frank (1996) pattern-oriented software Architecture.
- ^ ASP. NET MVC Overview
External links [edit ]
- An overview of the MVC pattern in Java from the Sun website
- Model View Presenter with Asp.net cod Eproject article.
- History of the evolution of MVC and Derivatives by Martin Fowler.
- ASP. Framework microsoft ' Scott Guthrie on. NET MVC
- Introduction to the ASP. NET Model View Controller (MVC) Framework scott Hanselman builds an application step-by-s Tep using the first CTP of the ASP Framework in this introductory Video
- holu b, allen. building user interfaces for object-oriented systems. Java World. 1999.
- Greer, Derek. "Interactive application Architecture Patterns", Ctrl-shift-b,.
- Building graphical User Interfaces with the MVC Pattern in Java
Hidden
Web Design |
|
Client |
Language |
- DHTML (HTML, CSS, JavaScript)
- HTML5
- VBScript (ie dedicated)
- Java Applet
- ActionScript (for Flash)
|
|
Technology |
- Web affinity ( Barrier-free web detection)
- No table page Design
- Responsive web-Design
- MVVM
- WYSIWYG
- Fault tolerance (graceful downgrade)
- CSS Sprite
- Dom
- Webgl
- MathML
|
|
|
Server-Side |
language |
- asp
- ASP. NET (C, VB. NET)
- JSP (Java)
- PHP
- CGI
- ColdFusion
&nbs P
- Perl
- Python
- Ruby
- Smalltalk
|
tr>
  |
technology |
- Web application framework
- AJAX
- mvc
- single page application
- crud
- REST
|
|
|
Application |
- Blog
- Network Forum
- Enterprise Portal site
- Electronic commerce
- Content Management System
- Electronic publishing
- Digital download
- Web Games
|
|
Other |
- Web Design
- Web applications
- Web browser comparison
- Search Engine Optimization
|
|
Classification:
- Software Design Patterns
- Mvc
Reproduced WIKI MVC pattern