First, Introduction:
The schema pattern is a common, reusable solution for problems that often arise in a given context in the software architecture. The schema pattern is similar to the software design pattern, but has a broader scope.
Model-View-controller mode, also known as MVC mode (Model View controller). Organize your code with a separate approach to business logic, data, and interfaces, and aggregate business logic into a single component, without the need to rewrite business logic while improving and personalizing the interface and user interaction. MVC is uniquely developed to map the traditional input, processing, and output functions in a logical graphical user interface structure. It divides a software system into three basic parts:
Model: The central data that is responsible for the storage system.
View: Displays information to the user (multiple views can be defined).
Controller: Handles the information entered by the user. Responsible for reading data from the view, controlling user input, and sending data to the model is the part of the application that handles user interaction. Responsible for management and user interaction control.
The view and controller together form the user interface.
And each view has a related controller component. The controller accepts input, usually as the time to encode the mouse movement, mouse button activity, or keyboard input. The time is translated into a model or attempted server request. The user interacts only with the system through the controller.
Second, the structure
The model component contains the application's functional kernel, which encapsulates the corresponding data and outputs the process of performing a particular application process; The model also provides functions to access the data, which are used by the view component that obtains the data to be displayed.
The controller invokes all of these procedures on behalf of the user.
Third, the purpose
The realization of a dynamic program design, is the subsequent modification and extension of the program to simplify, and make a part of the program reuse called possible.
By simplifying the complexity, the program structure is more intuitive.
Separates the internal representation of the information from the presentation of the information and accepts the user's request. It separates the components and allows for effective code reuse. That is, separating the implementation code of the model and the view so that the same program can use a different representation. For example, a batch of statistical data can be represented by a histogram, pie chart, respectively. C exists to ensure that the model and view are synchronized, and that the view should be updated synchronously once the model changes.
Iv. Features
An important feature of MVC is the separation of two types:
Separation of views and data models: use different views to present the same data, separate visual and non-visual components, and independently test the model. Because separating the visual components reduces the external dependencies to facilitate testing. (The database is also an external component)
Separation of view and Representation logic (Controller): A controller is a component that behaves logically, not a business logic component. MVC can be used as a pattern of expression as well as a constructive pattern, meaning that the controller can also be a business logic. Separate logic and concrete presentation, allowing for independent testing of logic.
Advantages: Low coupling, high reusability, low life cycle cost, deployment block, high maintainability, and advantageous software engineering management.
Cons: No explicit definition, not suitable for small, medium-sized applications, increased reusability of system structures and implementations, overly tight connections between views and controllers, inefficient access to model data, and generally advanced interface tools or constructors that do not support patterns.
V. Specific environment
Projects that require partitioning of modules.
Vi. issues to be resolved
Because PHP does not support object-oriented before, it is a procedural way to create, they will Model View Controller three layer of code mixed together, very confusing. So it solves the problem: maintenance is difficult, development speed is slow, two times the development difficulty is high, the workload is large, the code is reused, the coupling degree is high, the system is inflexible.
Vii. Solutions
In my understanding, the project is modular, divided into three parts: model, view and controller three parts. The model is an Application object and has no user interface. A view represents its display on the screen, representing the data flowing to the user. The controller defines how the user interface responds to user input, and is responsible for turning the user's action into a model-specific action. The Model reflects changes in the data by updating the view's data.
Viii. examples
applying to frameworks based on the MVC architecture pattern , the common server-side MVC framework is Struts, Spring MVC, ASP. NET MVC, Zend framework, JSF, common front-end MVC framework: ANGULARJS, Reactjs, backbone , there are other patterns that evolve from MVC, such as MVP, MVVM.
Here we illustrate Spring MVC:
Spring MVC is a powerful and flexible web framework provided by spring. With annotations, Spring MVC provides a development pattern that is almost pojo, making it easier to develop and test the controller. These controllers generally do not process requests directly, but instead delegate them to other beans in the spring context, which are injected into the controller through spring's dependency injection function. Spring MVC consists mainly of Dispatcherservlet, processor mappings, processors (controllers), view parsers, and views. His two cores are two cores:
Processor Mapping : Choose which controller to use to process requests
View Parser : Choose how the results should be rendered
With the above two points, Spring MVC ensures a loose coupling between the control processing request and how the view is selected to display the output.
Operating principle:
(1) HTTP request: Client request submitted to Dispatcherservlet.
(2) Find the Processor: the Dispatcherservlet controller queries one or more handlermapping to find the controller that handles the request.
(3) Call Processor: Dispatcherservlet submits the request to the controller.
(4) (5) Call the business processing and return the result: After the controller invokes the business logic processing, it returns Modelandview.
(6) (7) Process the view map and return the model: Dispatcherservlet queries one or more Viewresoler view resolvers to find the Modelandview specified view.
(8) HTTP response: The view is responsible for displaying the results to the client.
The Spring MVC framework is linked to the MVC schema pattern:
The implementation of the Controller interface specification is not involved in SPRINGMVC, and SPRINGMVC is implemented by calling handler to implement the controller layer.
SPRINGMVC uses the adapter mode, the front controller uses Handleradapter to invoke different controllers, and then the controller calls model to produce the data model;
The resulting data model will return back to the front-end controller, and the front-end controller will decide to render the page using a different template engine.
The difference between MVC architecture pattern and layered pattern
The MVC pattern is a category of design patterns, and as with other design patterns, patterns appear to be optimized for a function, and the MVC pattern can be seen as a subdivision optimization of the presentation layer in a three-tier architecture. In my understanding, the MVC pattern is the most commonly used architectural pattern in hierarchical mode to represent layers.
elaborated in detail as follows:
Strictly speaking, these three add up is the three layer architecture of the presentation layer, that is, MVC in the three layer architecture of the UI layer again differentiated, divided into a controller, view, entity three parts, the controller to complete the page logic, through the entity to the interface layer to complete the call, and C layer directly with the three layer of business logic layer dialogue. Layer three and MVC can coexist. Layer three is based on the business logic, and MVC is based on the page to divide.
The layered pattern of the three-tier architecture is a typical up-down relationship, with the upper layer dependent on the lower. But MVC, as a performance model, does not exist in the upper and lower relations, but is a collaborative relationship. Even if MVC is used as an architectural pattern, it is not a layered pattern. MVC and the three-tier architecture are basically not comparable and are applied to different areas of technology.
The difference between MVC architecture pattern and MVC framework
The MVC framework, which is mandatory to separate application input, processing, and output. using an MVC application is divided into three core parts: model, view, controller. Each of them handles their own tasks. The three core components that are used are in the MVC pattern. It is only in the framework that they are more independent of each other to deal with their respective tasks. The most typical MVC is the Jsp+servlet+javabean pattern.
In the MCV framework:
Views: A view is an interface that the user sees and interacts with, and the main elements of the view are Html,adobe FLASH,XHTML,XML/XSL,WML and other identity languages and Web services.
Model: Model data and business rules.
Controller: The controller accepts the user's input and invokes the model and view to complete the user's needs, so when you click a hyperlink in a Web page and send an HTML form, the controller itself does not export anything and do any processing. It simply receives the request and decides which model component is called to process the request, and then determines which view to use to display the returned data.
Xi. Examples of MVC architecture patterns
For example, ①, childhood play the kind of cassette game consoles, control is the host, generally I buy a host on the line, as long as he is not bad, he can always let me play this kind of game. The view is the TV and the game handle, the television can work independently, he regardless of input is the television signal, the DVD player signal or the game console signal, he just displays, and he decides how we see the effect is how, if I want a bigger or the color display effect, I just need to buy a corresponding TV set on the line, the handle can also be changed, the remote bar or with vibration. The model was a game cassette, and he decided what game I was playing, whether it was the bucket or the Super Mary, and the console and the TV maker never knew what kind of game it might run on. There may be game codes and storage units in the cassette, which are designed according to the needs of the game.
For example, ②, a simple information system using proportional representation for political elections, provides a spreadsheet of input data and several icons representing the current results. Users can interact with the system through a graphical interface. All information indicates that changes in the election data must be immediately reflected. (Referenced from the schema-oriented software architecture-Volume 1 mode system)
That is, once the model's data has changed, the model informs all views.
MVC Schema Pattern Detail description