Using Open Source Product Assembly Your Web Application Schema (1) Reproduction

xiaoxiao2021-03-06  64

Using Open Source Product Assembly Your Web Application Schema (1)

In fact, even if you use Java, it is not a very cumbersome web application, nor is a relaxed thing. There is a lot of things to consider at the beginning of the architecture. From the height, there are many problems in front of the developer: How do you think about how to build a user interface? Where to deal with business logic? How to persist. In this three-layer architecture, each layer has them to carefully consider. What technology should be used in each layer? What kind of design can loose coupling and flexible change? How to replace a layer without affecting the overall architecture? How do applications do all levels of business processing (such as transaction processing)?

Building a web application needs to understand many questions. Fortunately, many developers have already encountered such problems and have established a framework for processing such issues. A good frame has the following points: Reduce the burden of developers' handling complex problems ("Do not repeat the invention"); there is a good extension within; and there is a powerful user group that supports it. Good architecture generally targeted a certain type of problem and can do it well (Do One Thing Well). However, several layers in your program may need to use a specific framework, the completed UI (user interface) does not mean you can also couple your business logic and persistent logic to your UI section. For example, you should write JDBC code as your business logic in a Controller (Controller), which is not the controller. A UI controller should delegate other lightweight components that are given to the UI range. A good frame should be able to guide the code how to distribute. More importantly, the framework can liberate developers from the encoding, so they can concentrate on the logic of the application (which is important to customers).

This article will discuss how to combine several famous frameworks to make your application relax.

How to build your architecture and how to keep your application layers consistent. ? How to integrate the frame to allow each layer to work with each other with a loose coupling without tube low-level technical details? This is really a challenge for us. Here, discussing a strategy of integrated framework (using three popular open source frames): Standby We use struts; business strata us with Spring; while persistence is used. You can also replace other Framework as long as you get the same effect. See Figure 1 (Schematic of Framework)

Title of application

Most of the web applications can be divided into 4 layers in their duties. These four layers are: Presentation, Persistence, Business (Business) and Domain Model. Each layer should have a clear responsibility on the handler, and should not be mixed with other layers, and each layer is separated from other layers, but to put a communication interface between them. We started from the introduction of each layer, discuss what these layers should provide, and should not provide anything.

THE PRENTATION LAYER

In general, a typical web application should be a layer. Many Java senters also understand Struts. I am packed to org.apache.struts.action as a business logic. Therefore, we agree with a framework such as Struts.

Below is the Struts responsible:

* Manage the user's request to make a corresponding response.

* Provide a Controller to delegate the business logic and other upper-level processing.

* Treatment exception, throw Struts Action

* Provide a model for display

* UI verification.

The following provisions should not appear in the coding of the Struts display layer. They are independent of the display layer.

* Communication with databases, such as JDBC calls.

* Business logic and verification associated with your application.

* Things management.

In the representation layer introduces these code, it will bring high coupling and trouble maintenance.

THE PERSISTENCE LAYER

Another end of a typical web application is a persistent layer. It is usually the easiest way that the program is most likely to be out of control. Developers always underestimate the challenge of building their own persistent framework. The continuity layer inside the system not only requires a large amount of debugging time, but also the lack of functionality makes it difficult to control, which is a common problem of persistent layers. Also, there are several ORM open source frameworks to solve such problems. Especially hibernate. Hibernate provides Java with OR persistence mechanisms and query services, which also gives a Java developer who is familiar with SQL and JDBC API, and it is very convenient to learn. Hibernate's persistent object is based on Pojo and Java Collectes. In addition, using Hibernate does not hinder your Ide you are using.

Please see the entry below, you need to understand in the persistent layer code.

* Query the relevant information of the object's information. Hibernate completes the query through an OO query language (HQL) or the regular expression of the API. HQL is very similar to SQL - just replacing the table and columns in SQL with objects and its fields. You need to learn some new HQL languages; no matter what, they are easy to understand and the documentation is also very good. HQL is a natural language of an object query, which can learn it at a small cost.

* How to store, update, delete database records.

* Advanced ORM frames like Hibernate support most mainstream databases, and they support Parent / Child relationship, things handling, inheritance, and polymorphism.

Business Layer

The intermediate portion of a typical web application is a business layer or a service layer. From the perspective of the coding, this layer is the most easily ignored. And we often see the code for these business processing around the UI layer or persistent layer, which is actually incorrect because it leads to a close couch of the program code, so that these code is difficult to maintain over time. Fortunately, there are several Frameworks to exist for this issue. The most popular framework is Spring and PicoContainer. These are also known as MicroContainers, they can make you look good. These two frames have a simple concept of 'Dependency INJECTION (also we know' control reversal 'inversion of control = ioc). This article will focus on Spring's injection (translation: Through a setter method of a given parameter, it is different from factory, and Spring also provides setter incjection (type2), constructor inject (Type3) to we select. Spring puts the Objects, such as Transaction Management Handler, such as Transaction Management Handler, Object Factoris, Service Objects, and Service Objects, Service Objects, and Service Objects.

Behind we will give an example to reveal how Spring uses these concepts.

The business layer is responsible for:

* Handling the business logic and business verification of the application

* Management

* Allow interfaces that interact with other layers

* Manage the dependence of the target of the business layer.

* Add a flexible mechanism between the display layer and the persistence layer, so they do not directly link together. * BUSINESS SERVICES is obtained by revealing context from the display layer to the business layer.

* The execution of the management program (from the business layer to the persistence layer).

Domain Mode Block (THE DOMAIN Model Layer)

Since we are committed to an application that is not a very complex web, we need an object collection to move between different layers. The domain module layer consists of a business object in the actual requirement, such as ORDERLINEITEM, PRODUCT, and more. Developers don't have to manage those DTOs in this layer, only pay attention to Domain Object. For example, Hibernate allows you to put information in the database into the domain objects so you can display these data to the UI layer without disconnection. And those objects can also be returned to the continuous layer to update in the database. Moreover, you don't have to convert the object into DTOS (this may be lost in the transmission process between different layers), this model makes Java developers to use OO without the need to encode.

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

New Post(0)