This is my first day of the August Challenge

preface

Hi, everybody, I’m Helu.

Java is an object-oriented language with many noun objects, such as PO,VO,DAO… What do these nouns mean? Today, let’s talk about it.

Before explaining the various nouns, let’s put a picture first. After looking at the picture, we may have an intuitive feeling.

  • The user makes a request (perhaps to fill out a form), and the form’s data is matched as VO at the presentation layer.
  • The presentation layer converts the VO into a DTO required by the corresponding method of the service layer and passes it to the service layer.
  • The service layer first constructs (or reconstructs) a DO based on the DATA of the DTO and invokes the business methods of the DO to complete the specific business.
  • The service layer converts the BO to the persistence layer’s PO (either using ORM or not), calls the persistence layer’s persistence method, passes the PO to it, and completes the persistence operation.
  • A reverse operation, such as reading data, is transformed and passed in a similar manner.

directory

  • What is VO
  • What is DTO?

2.1 Differences between VO and DTO

2.2 Application of VO and DTO

  • 3. What is BO?

3.1 Differences between BO and DTO

  • What is PO?
  • What is DO?
  • What is DAO?
  • What is a POJO?

\

What is VO?

VO (View Object) : Display layer Object, usually an Object transferred by the Web to the template rendering engine layer.

What is DTO?

Data Transfer Object (DTO) : A Data Transfer Object, such as a Service or Manager, that is transmitted externally. It is usually used for data transfer between different architectural levels or subsystems, or for external interface parameter passing to provide data with different information at different granularity, so as not to cause confusion. But here, I’m referring broadly to the data transfer objects used between the presentation layer and the service layer.

2.1 Differences between VO and DTO

At the design level, VO and DTO are fundamentally different. DTO represents the data that the service layer needs to receive and return, while VO represents the data that the presentation layer needs to display. Therefore, the VO object may have fewer properties than the DTO object and may have different values. For example, the Servie layer has a method that retrieves user information and returns a DTO format in which the sex attribute is defined semantically: 1- male, 2- female, 0- unknown

{"name":" sex":"1" "age":"20"}Copy the code

For the display layer, it may need to use “handsome” to represent men, “beautiful” to represent women, “secret” to represent unspecified, and do not need to show age, so VO is

{"name":" name":" sex":" handsome"Copy the code

2.2 Application of VO and DTO

VO and DTO are different in concept, but in the actual project development, according to the specific business scenario, VO and DTO can be integrated into one (note: it is the implementation level), for example: When the requirements are very clear and stable, there is no need to distinguish between VO and DTO. In this case, VO can retire and just use a DTO. Why VO retire and not DTO? Going back to the design level, the service layer’s responsibilities should still not be coupled to the presentation layer, so, for the previous example, DTO for the “sex” property, the value still cannot be “handsome”, the transformation should depend on the page’s script (JS) or some other mechanism.

In some scenarios, VO and DTO need to coexist. For example, a page with a lot of content needs a “big view”, and all the data that makes up this big view needs to call multiple services and return multiple DTO to assemble.

3. What is BO?

Business Object (BO) : Business Object. Can be understood as a combination of PO, the main purpose is to encapsulate the business logic into an object, this object can include one or more other objects. For example, a resume, educational experience, work experience, social connections, etc. Educational experience can be matched with a PO, work experience with a PO, and social relationship with a PO. Then a corresponding BO can be established to process the resume. Each BO contains these pos, so that business logic can be processed for the BO.

3.1 Differences between BO and DTO

The first is the conceptual difference. A DTO is a data transfer object between the presentation layer and the service layer (you can think of it as a protocol between the two), while a BO is an abstraction of various business roles in the real world, containing both data and behavior, and is a complete object that can participate in the domain logic.

What is PO?

PO (Persistent Object) : Persistent Object, which forms a one-to-one mapping relationship with the data structure of the persistence layer (usually a relational database). If the persistence layer is a relational database, then each field (or several) in the data table corresponds to one (or several) attributes of PO.

A PO is a record in the database. A PO data structure corresponds to a table structure in the database. A record in the table is a PO object. In general, there’s no other method in PO than get or set, which is equivalent to Entity, and the two concepts are the same.

What is BO?

There are now two main versions of the DO concept.

  • One is the definition in Alibaba’s development manual. DO (Data Object) is equivalent to the above PO.
  • In DDD (Domain-driven Design), DO (Domain Object) is equivalent to BO above.

What is DAO?

DAO (Data Access Object) : Data access object, used to represent a data access object, using DAO to access the database, including insert, update, delete, query and other operations, used together with PO, DAO is generally in the persistence layer, completely encapsulating database operations, external exposure method makes upper-layer applications do not need to pay attention to any information related to the database.

It is mainly used to encapsulate the access to the database. Through it, POJO can be persisted into PO, and VO and DTO can be assembled with PO.

What is a POJO?

POJO (Plain Ordinary Java Object) : A POJO is a simple and Ordinary Java Object. After being persisted, a POJO is a PO, which is passed directly by it. The passing process is called DTO, and the corresponding representation layer is called VO.

The above mentioned PO, VO, and DTO are collectively referred to as POJos, while daOs and BO are not poJos.

conclusion

So far, I believe that everyone has a clear understanding of VO, DTO, DO, PO concepts, but in the actual development process, did not follow this concept to achieve, may be a VO class to walk the world. Because systems and systems have different levels of complexity and collaboration, there is no need to be dogmatic and apply all the concepts. You just need to have the same concept on the same team.

Thank you for reading, if the article is helpful to you, please also more like, retweet support. If there are any shortcomings, please comment in the comment area to correct, thanks ~~