"Java Architecture Learning" Model1 and Model2 discussions

Source: Internet
Author: User

In Java learning, the frequency of these two words appears very high, that is Model1 and Model2. So what is Model1 and what is Model2? Is it natural for us to accept these two concepts, but we don't know why? Today we will discuss, what is the Model1, what is the Model2, what is the difference between them?

Before I start, I'd like to say a little off-topic. I find that our study sometimes falls into such a situation, such as the emergence of a new concept, we will be very natural to accept, and then do not ask why to use it. When asked why this is the case? "I don't know, that's what I learned when I first learned it, so use it."

For example, when we first learned how to program, we knew we wanted to use the object to tune the new object. But this is the new process, do we really understand? For example, to new a user, we will write: User users = New user () know this write, all know that this can be new out of the User object, and then use this object to adjust the method is OK, is a very cured of a habit of thinking so that you adapt, know "Oh, I can come up with what I want with this writing, but why do you think this new idea? And this misunderstanding will be in the later study more and more brutal revealed. is to take for granted, and then do not add to the use of thinking to cure, which seems to be our common problem, at least, in my body has been a very good embodiment.

You know, we can muddle through at the beginning of learning, but there is a word, my teacher said, when a thing appears the first time, you can let it go, you can leave it when the second time, the third time you may look not only familiar but also need to study it well. so it's natural to accept, and now we're digging Model1 and Model2.

The reason I put MVC in a previous article is because this article is related to MVC, which we'll talk about later. In this article, we will make a good study of Model1 and Model2, and analyze the difference between them so as to better absorb the later content.

The following is a sequence diagram of Model1, which focuses on understanding its invocation process and how it consists of several parts.

This is the sequence diagram of the Model2. This is compared with Model1, Model1 seems to be very lame.

To understand Model1 and Model2, you have to pull out mvc. As the study progresses, we find that:

Model1 equivalent to Jsp+javabean;

Model2 equivalent to Jsp+servlet+javabean;

Maybe someone will ask, what is JavaBean? JavaBean is the model layer in the MVC design model, which is used to set the properties and behavior of the data, and then provides a Get/set method for getting properties and setting properties. So you look at the above two pictures, do you feel familiar with a lot?

So for Model1, its pattern is equivalent to Jsp+javabean, which puts the business logic in the view, and Model1 only contains M and v relative to MVC. From the entire invocation process, the JSP obtains the form data and submits it, invokes the business logic to process it, and returns it to the user after processing is completed. jsp,jsp Model1 is a JSP-centric add-on JavaBean, this development mode so that all business logic and interface display are dependent on the JSP, data collation by JavaBean complete. It's not safe, and it's not good to maintain. So model is suitable for small project development.

For Model2, it is the MVC development model. In fact, Model1 also to a certain extent, the implementation of MVC, that is, the JSP control layer and display layer into the JavaBean as the model layer, and Model2 the control layer servlet separate, specifically responsible for business Process control, accept page requests, Creates the required JavaBean instance and returns the processed data to the JSP. So for the whole invocation process: The servlet gets the form data and submits it, invokes the business logic to process it, returns the processed data to the Servlet,servlet and invokes the jsp pass parameter, and finally the JSP displays the result to the user. Therefore, it is suitable for large-scale project development for MODEL2.

Model1 and Model2 are the two specifications that Sun has introduced for the MVC model, in fact, there is no good or bad points, but in different times in order to adapt to the needs of different projects to make adjustments. Some projects suitable for use Model1 do, with Model2 instead appear clumsy, some projects Model1 do as Model2 come handy. Life is the same, everyone has their own expertise, their shortcomings, do not have to regret the more not to compare the winning and losing, the right to know themselves, in the appropriate life "big project" to show their own skills, is what we really should realize.

"Java Architecture Learning" Model1 and Model2 discussions

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.