Java Po and VO)

Source: Internet
Author: User
I have always had a conflict: whether PO can be used in the business logic layer as Vo, or whether to separate the two. In many forums, the competition between the two is fierce. So today I plan to write down my thoughts.
First, Java has several objects (PO, Vo, Dao, Bo, pojo)
I. Po: persistence object of persistant object. It can be regarded as a Java object mapped to a table in the database. Using hibernate to generate Po is a good choice.
Ii. VO: Value Object value object. It is usually used for data transmission between business layers. Like Po, it only contains data. However, it should be an abstract business object, which can correspond to a table or not, depending on the business needs.
One idea is that PO can only be used at the data layer, while VO can be used at the business logic layer and presentation layer. Each layer operation belongs to its own data object, which can reduce the coupling between layers and facilitate system maintenance and expansion in the future. If Po is used in each layer, it is equivalent to using global variables. We know that we strongly disagree with the use of global variables in OO design.
But every time you have to switch the VO-PO, it is really annoying. I think sometimes I can use PO in a business logic or presentation layer. At this time, the PO status does not change during this business logic process, for example, the business logic that shows the details of a product.
In developed projects, the scale is very small. I have always used Po as Vo, because Po is indeed very convenient, combined with hibernate Dao, I use Java's collection object as the carrier of value passing. Of course, Struts is also my best choice.
I think: In some intuitive and simple scenarios that are not easy to change and do not need to involve multiple Po, it is better to use the Po to pass the value, this reduces the workload (which means to reduce bugs and risks), and does not need to worry about future maintenance work.

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.