The difference between VO, BO, PO, DO, DTO

With the deepening of the programming industrialization level, various programming models emerge in endlessly (such as MVC, MVP, etc.), and along with these programming models, a large number of new concepts flock in. What is the difference between VO, BO, PO, DO, and DTO? Kind of like, these new concepts have always been in the clouds. Although there are many articles on the Internet to distinguish these concepts, it seems that they are basically reprinted from several identical articles, and these articles themselves are also unclear. , some contradict each other, and some articles use these concepts in the simplified system, which makes people more and more confused.

Facing this picture, let us start with the DTO that connects the past and the future.

DTO (Data Transfer Object) data transfer object

This transmission usually refers to the transmission between the front and back ends

DTO is a special object, it has two forms of existence:

On the back end, its existence form is a Java object, that is, an object defined in the controller. Usually, the back end does not need to care about how to convert from json to java object. This is done by some mature frameworks, such as the spring framework;

On the front end, its existence form is usually an object in js (it can also be simply understood as json), that is, the data body requested through ajax.

That's why it's drawn across two layers

There may be a problem here. Now that microservices are prevalent, can the transfer object called between services be called DTO?

An implicit meaning of DTO itself is to be able to fully express the output of a business module,

If the service is relatively independent from the service, it can be called DTO;

If services are not independent, each is not a complete business module, and disassembly may only be due to computational complexity or performance issues, then this cannot be called DTO, it can only be BO.

VO (View Object) value object

VO is the data used for display, no matter the display method is a webpage, a client, or an APP, as long as the object is visible to others, it is called VO

The main form of existence of VO is the object in js (it can also be simply understood as json)

The difference between VO and DTO

There are two main differences:

One is that the fields are different, and VO will delete some fields as needed;

The other is that the values ​​are different, and VO will explain the display business of the values ​​in DTO as needed;

As a simple example,

DTO could be like this:

{
    "gender":"男", 
    "age":22 
} 

For business one, only gender is needed, and because it is an ancient chat room, men cannot be directly displayed, so after business explanation, the VO of business one is as follows:

{ 
    "gender":"公子" 
} 

For business 2, only the age is needed, and the exact age is not required, so the VO of business 2 is explained as follows:

{ 
    "age":"20~25" 
} 

PO (Persistent Object) persistent object

Simply put, PO is a record in the database. The data structure of a PO corresponds to the structure of the table in the library. A record in the table is a PO object.

Usually PO has no other methods except get and set methods

For PO, the number is relatively fixed and must not exceed the number of database tables, which is equivalent to Entity, and the two concepts are consistent.

BO (Business Object) business object

BO is a combination of PO. For example, PO is a transaction record, and BO is a collection of all transaction records of a person. For a more complex example, PO1 is a
transaction record, PO2 is a login record, PO3 is a product browsing record, and PO4 is an add Shopping cart records, PO5 is search records, BO is a personal website behavior object
BO is a business object, a class of business will correspond to a BO, there is no limit on the number, and BO will have many business operations, that is to say, in addition to get, set In addition to methods, BO has many methods for calculating its own data.
Why is BO also drawn across two layers? The reason is that many persistence layer frameworks now provide the function of data combination, so BO may be formed by assembling PO at the business layer, or it may be directly generated by the framework at the database access layer in order to pursue queries
. Efficiency. It is very common for the framework to skip PO and directly generate BO. PO is only used for addition, deletion, and modification.

The difference between BO and DTO

The difference between the two is mainly that the fields are deleted
. BO is internal. In order to perform business calculations, auxiliary data is required, or a business has multiple external interfaces. BO may contain a lot of data that is not needed for external interfaces. Therefore, DTO On the basis of BO, as long as the data you need, you need to provide it to the outside world.
In this relationship, there is usually no change in the data content. The content change is either completed during the internal business calculation of BO, or when explaining VO

What is DO?

What about DO, isn't there a DO in the title?
The above concepts have basically covered all the processes, DO is only the same as one of the concepts,
but which concept is the same?
Now there are mainly two versions.
One is the definition of
DO (Data Object) in Alibaba’s development manual, which is equivalent to the above PO,
and the other is DO (Domain Object) in DDD (Domain-Driven Design),
which is equivalent to BO above

Practical application
These concepts are very complete, do we have to follow this when we use them?
Of course not, the complexity of the system is different from the system, and the level of collaboration is different. There is no need for dogmatism.
I will give some practical suggestions on which concepts to use
and which ones to save. Entity, no matter what you have to have
2, some tool systems and some systems with less complex business DTO can be merged with BO into one, when the business expands, pay attention to splitting 3,
VO can be optimized first , if the display business is not complicated, you don’t need it at all. Use DTO
4 directly. This is also the most important one. The concept is for people. When multiple people collaborate, you must ensure that everyone’s concepts are consistent. who you work with

Reprint: An article clarifies the difference between VO, BO, PO, DO, and DTO- Know about

Guess you like

Origin blog.csdn.net/m0_60252632/article/details/124267535