The highly abstract MVC ignores the following detailed descriptions and brings about hidden risks.

Source: Internet
Author: User

The highly abstract MVC ignores the following detailed descriptions and brings about hidden risks.

The highly abstract MVC ignores the following detailed descriptions and brings potential risks.

Beautiful Life of the sun and fire god (http://blog.csdn.net/opengl_es)

This article follows the "signature-non-commercial use-consistency" creation public agreement

Reprinted please keep this sentence: Sun huoshen's beautiful life-this blog focuses on Agile development and mobile and IOT device research: iOS, Android, Html5, Arduino, pcDuino, otherwise, this blog post is rejected or reprinted. Thank you for your cooperation.


As for "for MVVM, I want to say: if you do your own thing, the Controller will be simplified!" As shown in the following figure:


MVC is the final result of software iteration; it is also the backbone, ignoring the details; and it is highly abstract, ignoring the differences in specific implementations;

As a result, these neglected parts, or some or none of them, have encountered many unexpected vicious consequences;

MVC itself is dynamic. It must have different choices to adapt to different environments and complexity;

It is difficult to abstract because of its wide adaptability;

However, to be widely transmitted, it must be highly abstract and trade-offs;

The result is that the applicable and effective parts are abstracted;

The Guiding Significance of the details is indeed ignored;


In general, MVC is dynamic, scalable, and a summary of practices. There is no way to truly use the three letters of MVC to express integrity. MVC is only a landmark.

Then, the true embodiment of MVC is that it is dynamic and constantly expanded to separate the data and presentation structure!



Simple applications, the box section, all the logic in the View Controller, there is not much to say;

For complex applications, the box section should not contain any content related to the actual view or data. These parts should be incorporated into each subclass and completed separately;

Complex applications, in the box section, can only see the business logic, which is also inherent in many elegant Java projects;

This is right if you do not understand the business logic or the Code context;





The following MVC modes are introduced:

The MVC mode is short for "Model-View-Controller". The Chinese translation is "Mode-View-Controller ". The MVC application is always composed of these three parts. Event causes the Controller to change the Model or View, or change both. As long as the Controller changes the data or attributes of Models, all dependent views are automatically updated. Similarly, as long as the Controller changes the View, the View will retrieve data from the potential Model to refresh itself. The MVC pattern was first proposed by the smalltalk Language Research Group and applied to user interaction applications. Smalltalk and java have many similarities. They are all object-oriented languages. Naturally, SUN recommends the MVC pattern as the Architecture Pattern for developing Web applications in the petstore case applications. The MVC mode is an architecture mode that requires collaboration between other modes. In the J2EE mode directory, the service to worker mode is usually used, while the service to worker mode can be composed of the centralized controller mode, the dispatcher mode, and the Page Helper mode. Struts only implements the View and Controller of MVC. The Model must be implemented by the developer. Struts provides the abstract class Action to enable the developer to apply the Model to the Struts framework.
The MVC pattern is a complex architecture pattern, and its implementation is also very complicated. However, we have come to an end with a lot of reliable design patterns. The combination of multiple design patterns makes the implementation of the MVC pattern relatively simple. Views can be seen as a tree, which can be implemented by Composite Pattern. The relationship between Views and Models can be reflected by Observer Pattern. The Controller controls the display of Views, which can be implemented using Strategy Pattern. Model is usually a Mediator and can be implemented using Mediator Pattern.

Now let's take a look at the position of the three parts of MVC in the J2EE architecture, which helps us understand the implementation of the MVC model. The relationship between MVC and J2EE architecture is: View is in the Web Tier or Client Tier, usually JSP/Servlet, that is, the page display part. The Controller is also in the Web Tier, which is usually implemented using Servlet, that is, the logic part of page display. The Model is in the Middle Tier. It is usually implemented using the server's javaBean or EJB, that is, the implementation of the business logic.

I. MVC design ideas

Model-View-Controller (MVC) separates the input, processing, and output processes of an application in the form of Model, View, and Controller, such an application is divided into three layers: model layer, view layer, and control layer.

A View represents a user interaction interface. For Web applications, it can be summarized as an HTML interface, but may be XHTML, XML, or Applet. With the complexity and scale of applications, interface processing becomes challenging. An application may have many different views. The MVC design mode can only process view data collection and processing and user requests, it does not include the processing of business processes in the view. The processing of business processes is handed over to the Model. For example, an order view only accepts and displays data from the model to the user, and transmits input data and requests from the user interface to the control and model.

Model: Processes business processes/states and formulates business rules. The processing process of a business flow is black box for other layers. The model accepts the data requested by the view and returns the final processing result. The Design of business models is the core of MVC. Current stream... the remaining full text>

Development Trend of mvc

The MVC method is usually used to create user interfaces in Smalltalk. Through the design patterns in MVC, we can help you understand what we mean by "Patterns.

MVC includes three types of objects. Model is the application object, View represents the screen, and Controller defines the processing (response) method for user input. Before applying the MVC method, the functions of these three objects are usually combined. The application MVC separates them, providing flexibility and reusability for the design.

MVC separates the view and model objects by establishing the Subscribe/Notify protocol between the view and model. The View object must ensure that its representation reflects the state of the model object. When the data of the model object changes, the model object notifies the view object as a response to this behavior, each view object has an opportunity to update it. This method enables multiple view objects to provide different representations for a model object. You can also create a new view object for the model object without re-writing the model. Demonstrate a model and three views:

On the surface, this example reflects a design that separates view from model. However, this design is suitable for a more common problem: reduce the coupling between objects, so that when an object changes, it will not affect another object, you do not even need to know the implementation details of other objects. This more general mode will be described in the Observer mode.

Another characteristic of MVC is that view objects can be defined in nesting mode. For example, the control panel of a button can be implemented by a complex view object containing nested button view objects. the user interface of the object observer can be composed of nested view objects that can be reused in the debugger. MVC adopts the CompositeView class (subclass of View) to support nested view. Its behavior is the same as that of the view object and can be used in any scenario where the view object can be used.

As a result, we can look at this way to treat a composite view as a design (method ). Similarly, this design can abstract another type of more common problem (solution): in some cases, we divide objects into groups and process a group like an individual object. This method is described in Composite design mode. It allows you to create a class hierarchy. At this level, some sub-classes define the original object (such as Button), while other classes can define the CompositeView ), merging objects can assemble original objects into more complex objects.

Similarly, MVC can change the way the view class reacts to the user without changing its visual representation. You may want to change the keyboard response method, for example, replacing the command key with a pop-up menu. MVC encapsulates this reaction mechanism as a control object (Controller ). The Controller has a class hierarchy, which is easy to create a variant-a new controller from an existing controller.

View objects use instances of a controller object to implement specific response policies. To implement different policies, you can simply use different controller instances to replace the current instance. You can even change the view controller at runtime to change the response (policy) of the view object to user input ). For example, a view object can be set to disabled, which does not respond to user input. To achieve this goal, you only need to let the Controller ignore all input events.

This view-controller relationship is a typical example of the Strategy design model. Strategy is an object that represents an algorithm. This is especially useful when you want to replace an algorithm (either static replacement or dynamic replacement), which may have many variables or complex data structures.

Other design modes are also used in MVC. For example, the default controller class of the view is described in the Factory Method mode, and the scroll bar is added to the view in the Decorator mode. But the main pattern in MVC is the aforementioned... the remaining full text>

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.