Almost all Java-based web apps require Model 2 (Part i)

zhaozj2021-02-12  150

Almost all Java-based web apps require Model 2

In terms of web applications, Java developers usually use two design patterns, simply called Model 1 and Model2. Two modes are now applying, but in the development of large and medium-sized applications (translation: refer to application, representing Web Applications) or complex future possible applications, you should first push MODEL 2. I will talk about MODEL 2 architecture and implement Model 2 architecture MVC (Model-View-Controller) design mode. I want to explain why Model 2 is the first push mode and provides a simple application that implements this mode.

You use the Model 1, which is a page-centered. Applicable to completing simple applications or if you want to quickly complete some things. Apply this mode has a series of JSP pages, in these pages Run from a page to another. Because it is easy, this is a model that you often use when you begin school JSP. The main problem with the Model 1 application is difficult to maintain, and there is no flexibility, in addition, due to development The personnel have been involved in the encoding of page development and business logic, which is difficult to achieve labor division between page designers and web developers.

Model 2 is the architecture of a large application. It is a Model-View-Controller (MVC) mode. This mode is the main concept of the SmallTalk-80 user interface. At that time, "pattern" is not used, it is MVC paradigm.

The MVC mode consists of three major classification: Model, view, controller. The model represents application objects or data, the view is the display of the model, the controller (Controller) is paying attention to the user interface and User input information interaction. Before the MVC mode, these three parts exist in a class to make the application lose flexibility and reuse.

The MVC mode implements a loose grinding between views and models. The model is simple to encapsulate the application object - it does not know anything about the view. On the other hand, the view is the visual expression of the model and depends on the model. The view contains a reference to the model instance, and the controller is the same.

In order to better understand the MVC mode, let's consider Microsoft's Excel spreadsheets, in it, data can be manifested in the form of a pie chart or line chart. The pie charts and line charts here are views, they visualize the same batch of data. The controller sends a command to the model and view through the user's input information.

Unlike the relationship between view and model, the view and the controller have a more close relationship. A view is usually transmitted to the controller object as a reference and he can access some variables in the controller. If you want to know more about the MVC mode, please see Steve Burbeck, Ph.D. "Applications Programming in SmallTalk-80: How To Use Model-View-Controller (MVC)."

Model 2 composition

Now, return to the Model 2 architecture, in the MVC mode, we have a servlet to play the role of the controller (see Figure 1) .Jsp page is usually used as an application view, we use a package business logic Javabean as a model.

Last continued

Translated by windowsdna

转载请注明原文地址:https://www.9cbs.com/read-6196.html

New Post(0)