Layered principles in web development and data transfer between tiers

Source: Internet
Author: User

Most of the current Web application are based on the B/S model of the three-tier architecture development, where the three-tier architecture refers to the Web layer, business layer and data access layer. There are many benefits to adopting a tiered approach to development, and here's a simple two point:

(1) Tiered development enables different developers to focus on the specific aspects of their expertise and to help develop quality systems. Because few programmers can master everything from js,css,dhtml to struts to hibernate to the final database design, all the techniques to be used by the development process. Everyone has their own responsibilities, pay attention to the level of their good, which is more than a person or a group responsible for a module from the page to the bottom of the development method is much better.

(2) Layered separation of logic, so that the system structure level clear, the system becomes flexible and easy to maintain. The developer should try to keep the relatively independent loose coupling state between each layer of the system, which is the necessary condition to realize the layering, and also the important guarantee of constructing the good structure system.

The following focuses on the issue of data transfer between tiers. Before discussing this question, I think it is necessary to clarify several concepts, namely VO, PO, POJO, BO, DAO, DTO.

(1) Vo: Value object, and there are also those who think that VO refers to the view object, or that it is also a representation of two concepts.

(2) PO: Shingju objects (Persistence object)

(3) POJO: (Plain old Java object) literal meaning should be unformatted traditional Java objects. For this concept I see a lot of people on the Internet do not understand, some people even think of it as a po, in my personal understanding, I think pojo is a relative concept, as its literal meaning, it refers to an ordinary Java object, this concept is mainly used and like Java The bean is created in such a way that the Java objcet of a particular specification is differentiated.

(4) BO: Business Objects (Business object), it is wrong to think of Bo as a data object manipulated by the business layer, Bo refers to objects that encapsulate the business process logic (the instances of those classes that we want to implement in the service layer) and the data object that the business layer manipulates is actually vo.

(5) DAO will not have to say more (data Access object),

(6) DTO: (Data transfers object) data transfer objects. This concept is also relatively well understood, the actionform in struts is actually a dto, used to transfer data between the page and the action.

(7) In addition, if VO is understood as a View object, then Actionform even Vo. There seems to be an object called Qo on the internet, which I think should mean query object, but I don't seem to have seen much of it.

To understand the above concepts, I would like to say that the two days have been considering the problem, that is, the data objects at each layer to the layer and layer of the transmission problem.

data Objects manipulated between tiers:

(1) Web layer (jsp/action): Actionform

(2) Business level: VO (Note: If we use hibernate then I can use it to generate a PO to replace the business layer Vo, this is because the structure of VO and Po is almost no different, and due to the powerful features of Hibernate, So that its PO can be left out of the persistence layer and exist. Be aware that not all ORM tools have this capability: for example, jdo1.x is not possible.

(3) Data access layer: PO.

The following is a detailed explanation:

(1) Actionform is the data representation of the Web layer, he cannot be passed to the business layer

(2) PO is a persistent layer of data representation, in certain circumstances, such as hibernate, he can replace VO in the business layer, but neither PO nor VO must be restricted to use within the business layer, and the control (that is, action) that reaches the web level cannot be spread to view.

(3) The data transformation between Actionform and Po is performed in action.

In fact, each layer has its own specific data object, instead of each layer sharing a structure of data objects, so that each layer will be heavily coupled before. Between the adjacent layers, there should be an operation that receives the data object from its upper or lower layer and extracts the required data from it into the data object to be manipulated in its own layer. This is done in action, for example, but is omitted because the business layer and the data access layer use the same data access object.

The focus here is action, and the work we do with the action is to accept the actionform from the page, extract the data, encapsulate it into the PO, and then call the Business layer component (BO) to implement the relevant business, and finally the page jump.

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.