MVC pattern and j2e typical three-tier architecture

Source: Internet
Author: User

First of all, to introduce to the reader the MVC architecture,MVC is a desktop program from the architecture model, its basic idea is to separate the program interface and business logic, so as to facilitate the late maintenance of software, At the same time, it is convenient for the development period Division of labor and Management,MVC has a lot of it is now widely used in Web development.

    Here's a look at your experience with the MVC Architecture, and some of the pitfalls that make it easier for readers to understand what MVC ; my first Contact MVC is learning PHP in the process, PHP The is a classic Web development language can, for some small and medium-sized non-server-based computing as the core of projects, ashamed now know what they learned before PHP of MVC The is a misunderstanding. mvc literal meaning is simply the model ( M ), view ( V ), CONTROLLER ( The purpose of the C ) view is to present the results of the program run to the user, and the model is to implement the user's business logic, mainly to receive the user's parameters, complete some operations, and access the database. MVC is an idea, a horizontal hierarchy, mvc php is more mature and more reasonable, plus the features of Java (Superior cross-platform) can take advantage of MVC The builds a very powerful cluster system.

    the mvc on java ee , again, to emphasize MVC is a horizontal layering of ideas, with such a amount of thought you can build a variety of systems, as long as based on this idea can be, can have different implementations, java EE in the view layer general use JSP , of course, you can also use Html+ajax technology to implement a highly interactive asynchronous communication Web apply; model layer is used JavaBean as the principal, implement Java The business logic for the , and the controller for the servlet implementation, so that the overall java EE The provides different standards for different roles, making it easier for programmers to develop.

Let's talk about the three-layer architecture pattern that three layers often hear, first to reiterate that the three-tier architecture and MVC are two concepts that beginners can easily think of as a concept, that MVC is a three-tier architecture, and that the three-tier architecture is MVC , it will make you confuse many concepts, and there will be some difficulties in understanding the system. The three-tier architecture is divided into the presentation layer, the logical layer, the persistence layer, where the presentation layer is a web -related development, corresponding to the MVC View and the controller, and of course java EE the filter in is also part of the presentation layer, although it has nothing to do with the logo, but his implementation is a crosscutting technique that will Request the request as a filter, filtered later to the controller, the controller calls the business logic and the view layer as needed to display to the user, so the filter is divided into the presentation layer, mainly because he belongs to Web technology, and is above the control layer. The logical layer and the persistence layer are for the portability of the program we divide the model layer in MVC into a logical layer dedicated to computing and a persistence layer dedicated to accessing the data, including access to the database, access to XML, and access to other files that can persist data, etc.), the business logic layer is mainly JavaBean Implementation, and the most common of the persistence layer is DAO, which encapsulates all the operations of the database. In fact, the three-tier architecture is a vertical hierarchy from the structure, the upper layer relies on the lower layer, and the lower layer does not depend on the upper layer, that is, single dependency.

To summarize,MVCis a horizontal hierarchical model of the system, and the three-tier architecture is a vertical hierarchy,MVCis a kind of thought, realizes theMVCthe user should not be directly accessibleJSP(view), even if you do not need to invoke the business logic implementation function, you should let all the user's actions go through the controller, and the controller jumps to the view. The three-tier architecture is a vertical layer that seals the entire system3layer,3layer from the top to the bottom of a single dependency, where the logical layer is the core, the implementation of the main functions of the system, the other two are mainly to achieve the system amount of expansion, such as the system needs to replace the display interface only need to change the view, if you need to change the database, you only need to change the persistence layer, Do not change the program's core code (logical layer). This architecture is primarily suitable for large-scale project architectures, where designers can design projects flexibly based on the size of the project, for example by using the simplestJSPdirect access to the database's schema mode,Jsp+javabean(Sunof theModel1),mvc+1(that is, Horizontal pressMVCschema architecture, only one level of portrait--servletdirect access to the database),mvc+2(that is, Horizontal pressMVCschema architecture, vertical only two layers--servletcall the logical layer to access the database),mvc+3(that is, Horizontal pressMVCpattern architecture, only three layers vertically--servletinvoking the business logic, the business logic accesses the database); Of course, different architectures apply to projects of different sizes, depending on the project situation.

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.