Presentation Layer (JSP), persistence layer (like DAO), Business layer (logical layer, service layer), model (JavaBean), Control layer (action)

Source: Internet
Author: User

Transferred from: http://www.blogjava.net/jiabao/archive/2007/04/08/109189.html

In order to achieve loose coupling between the web layer (struts) and the persistence layer (Hibernate), we adopt two modes: Business Rep (Delegate) and DAO (Data Access Object). In order to reduce the coupling between business logic and data Access logic, the DAO pattern reduces the coupling between the business object and the framework when a persistent framework is applied, so that we can choose different implementations of the persistence layer framework without modifying the business object. In fact, there are two structural modes in the DAO Pattern: Bridge mode and Adapter (Adaptor) mode.

for the presentation layer, we use Struts ; business Layer Usage Spring for the persistence layer we are using Hibernate . You can replace a frame here and use your favorite frame to achieve the same effect. Shows the views viewed from the highest level when the framework is integrated.

Application Layer

Many well-designed web applications can be divided into four tiers according to their responsibilities. These levels are the presentation layer, the persistence layer, the business layer, and the domain model layer. Each level has its own unique responsibility and cannot mix its functions with other levels. Each application layer should be isolated from the other layers, but allows communication between layers using an interface. Let's take a look at each layer and discuss what each of them should provide and what should not.

Presentation Layer

The end of a typical Web application is the presentation layer. Many Java developers know what struts provides. However, too often, the coupling code, such as business logic, is put into the org.apache.struts.Action. So let's summarize what a framework like struts should offer. Here's what struts is for:

    1. Manage requests and responses for users
    2. Provides a control to delegate calls to business logic and other upstream processing
    3. Handling exceptions from other layers that throw exceptions into the struts Action
    4. Assemble model objects that can be represented in a view
    5. Perform UI validation

Here are some things that you can often encode with struts but should not be associated with the presentation layer:

    1. Interact directly with the database, such as the JDBC call
    2. Application-related business logic and validation
    3. Transaction management

Introducing these types of code into the presentation layer will result in type coupling and maintenance burdens.

Persistence layer

The other end of a typical Web application is a persistence layer. This is also the easiest place in the app to get out of control quickly. Developers often underestimate the challenge of building their own persistence layer framework. A custom, internally developed persistence layer requires not only a lot of development time, but also often lacks functionality and is difficult to manage. There are many open source Object relational Mapping (ORM) frameworks that address these issues. In particular, the Hibernate framework allows for object-relational persistence and query services in Java. Hibernate has a moderate learning curve for Java developers who are already familiar with SQL and JDBC APIs. Hibernate's persistent objects are based on Pojo and Java Clusters (collections). Also, using hibernate does not work with your IDE interface. Here's a list of the types of code you need to write in the persistence framework:

    1. Queries the relationship information into the object. Hibernate is done with the OO query language called HQL, or by using a more expressive rule API. In addition to using objects instead of tables, using fields instead of columns, HQL is very similar to SQL. There are also some new specific HQL language features that need to be learned, but they are easy to understand and well written. HQL is a natural language used to query objects, and objects require little learning curve.
    2. Store, update, and delete information stored in the database
    3. Advanced Object-relational mapping frameworks such as hibernate support for most major SQL databases, they support parent/child relationships, transactions, inheritance, and polymorphism.

Here are some things that should be avoided in the persistence layer:

    1. The business logic should be placed in the higher level of the application. Only data access methods are allowed here.
    2. You should not decouple the persistent logic from the performance logic. Avoid expressing components such as JSP or the logic in a servlet-based class to communicate directly with data access. By isolating the persistence logic in its own layer, the application will have more flexible modifications without affecting the code of the other layers. For example, hibernate can use other persistent frameworks and APIs instead of modifying the code in other layers.

The business layer should be responsible for the following issues:

      1. Business logic and business validation for processing applications
      2. Management transactions
      3. Interfaces that allow interaction with other layers
      4. Managing dependencies between business-level objects
      5. Added flexibility between performance and persistence layers so that they do not need to communicate directly with each other
      6. Exposing the context from the presentation layer to the business layer for business services
      7. Manage the implementation from the business layer to the presentation layer

Presentation Layer (JSP), persistence layer (like DAO), Business layer (logical layer, service layer), model (JavaBean), Control layer (action)

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.