Several web development models-MODEL1, MODEL2, layer three

Source: Internet
Author: User

At present, the most important thing in the object-oriented thinking is "abstraction", and the most important thing in the software design goal is "to respond to changes in demand (increase or change)".

Think about it, whether it is "layered" thinking, or "design pattern" thinking, or "generic" ideas, etc., it should be said that the ultimate goal is to "respond to changes in demand", and are filled with "abstraction."

Stratification is to make "big change small, easy to change", and for different realities, it can evolve the ever-changing prototype. Stratification is a kind of thought, and Model1, Model2, three layers are the most commonly used prototypes that have evolved from layered thought (experience summed up). They are all "layered thinking".

The following three types of development models are introduced:

Model1

  

This model is the most commonly used by our beginners, because it built less class files, development more casual, JSP can both write HTML and can write server-side code, so beginners very much favor this model. However, this model mixes the "business layer" with the "presentation layer", which is written in JSP, which makes JSP responsibilities too heavy. Because "performance" and "Business" are mixed, so it greatly weakened its "response to demand change" ability. This also violates the original purpose of Sun launch JSP. However, if a project is small and the demand is stable, it is suitable for this architecture model.

Model2 (MVC)

   

The above mentioned in the MODEL1 Design model JSP responsibility is too heavy, contrary to sun originally launched the purpose of JSP. According to Sun's own recommendation, the JSP should only store the "display layer" related things, that is, only the portion of the output HTML page. But all the data calculation, data analysis, database connection processing and other "business layer" things are not JSP responsibility. So the MODEL2 model solves this problem, all the "business layer" related things are put into the servlet, JSP just do a single function of rendering the page.

The MODEL2 model contains the application of the famous MVC, which consists of the business logic and persistent data, which is played by the common Java class, the view layer is displayed only, the JSP acts as the controller, the controllers layer takes the form data, integrates the business logic, and turns to the view page. Acted by the servlet.

Model2 separates the control on the basis of Model1, which makes JSP and servlet perform their duties. Thus, compared with Model1, it can better deal with the change of demand. This model is more suitable for large-scale project development, because large-scale project needs change more, need to deal with the need to increase, modify and so on.

Three Floor

   

The above is a very classic three-tier architecture, which, from the diagram, draws a layer of "persistent logic" from the MODEL2 model. As for the reason, it is very simple, because the MODEL2 model mixes "data access" with "business logic" so that coupling cannot be lifted, which means that the logic of "data access" cannot be abstracted, so changes in "data access" logic (such as replacing a database) will inevitably cause "business logic" Changes, and in reality the "Data Access" logic is a very easy place to change, so separate the "data access" into one layer of "persistent logic". This makes it possible to abstract each of the layers that are susceptible to change, thus moving from dependency to implementation to dependency on abstraction to better respond to changes in demand.

The dependencies between layers and layers are as follows:

   

There is a top-down, single dependency between each layer. The principle of partitioning is to take the volatile point out of a single layer, so that the point of change can be abstracted, from the dependency implementation to the dependency abstraction, so as to achieve the "response to demand change". It is a more formal model of development.

Summary

Be aware that the need to respond to changes in demand is to abstract the point of change, and want to abstract it is necessary to first extract the point of change (that is, layering).

The Model1, Model2, and three-tier architectures are commonly used three design models derived from "layered thinking" combined with "experience" to deal with most of the development scenarios in real life. We can use the "abstract" method to achieve the goal of "responding to demand changes".

Several web development models-MODEL1, MODEL2, layer three

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.