当前位置:网站首页>Division of entity classes (VO, do, dto)
Division of entity classes (VO, do, dto)
2022-07-27 15:50:00 【Qualified programmer】
Often exposed to VO,DO,DTO The concept of , This paper is from the perspective of entity division in domain modeling and practical application in project , A brief analysis of these concepts .
The main conclusion is : In project application ,VO Corresponding to the data to be displayed on the page ( Forms ),DO Corresponding to the data stored in the database ( Data sheet ),DTO Corresponds to data that needs to be passed in addition to both .
One 、 Entity class
The definition of entity class in Baidu Encyclopedia is as follows :
The main responsibility of the entity class is to store and manage the information inside the system , It can also have behavior , Even complex behavior , But these behaviors must be closely related to the entity object it represents .
According to the above definition , We can see , Entity classes have two aspects , Storing data and performing operations related to the data itself . These two aspects correspond to the implementation , The simplest entity class is POJO class , Contains attributes and their corresponding set and get Method , The common methods of entity classes are also used to output their own data toString Method . 
Two 、 Entity classes in the domain model
There are four types of entity classes in the domain model :VO、DTO、DO、PO, Various entity classes are used for interaction between different business levels , And will realize the transformation between entity classes in the hierarchy .
Business stratification is : View layer (VIEW+ACTION), Service layer (SERVICE), Persistence layer (DAO)
The transfer of entities between corresponding layers is shown in the figure below : 
We don't strictly follow this transmission relationship in the project , However, this association with the business level is helpful for us to understand the role of various entity classes .( We didn't touch PO Why , I understood as a ORM Yes PO It was packaged )
The following is the original material , The above figure is drawn based on this :
Concept :
VO(View Object): View objects , For display layer , Its function is to put a specified page ( Or component ) All the data of .
DTO(Data Transfer Object): Data transmission object , This concept comes from J2EE Design mode of , The original purpose was to EJB Distributed applications provide coarse-grained data entities , To reduce the number of distributed calls , This improves the performance of distributed calls and reduces network load , But here, , I refer generally to the data transfer objects used between the presentation layer and the service layer .
DO(Domain Object): Domain object , A tangible or intangible business entity abstracted from the real world .
PO(Persistent Object): Persistent object , It follows the persistence layer ( Usually a relational database ) The data structure of the , If the persistence layer is a relational database , that , Each field in the data table ( Or several ) As the corresponding PO One of the ( Or several ) attribute .
Model :
Next, we will build a simple model with a sequence diagram to describe the location of the above objects in the three-tier architecture application
l Request from user ( It could be filling out the form ), The data of the form is matched as VO.
l The display layer puts VO Transform to what the service layer corresponding method requires DTO, To the service layer .
l The service layer first bases on DTO Data structure ( Or reconstruction ) One DO, call DO Business method to complete specific business .
l The service layer put DO Convert to persistent layer PO( have access to ORM Tools , It can also be done without ), Call the persistence method of the persistence layer , hold PO Pass it on , Complete the persistence operation .
l For a reverse operation , Such as reading data , It's a similar way of transformation and transmission , A little .
3、 ... and 、 Entity classes in the project
Common entity classes in projects are VO,DO and DTO, Naming rules also often end with the corresponding string , Such as *VO.Java. however DTO Don't always follow this rule , And usually related to his purpose , As written *Query.java, Indicates that a query condition is stored . The business hierarchy of entity classes in the project is not so strict , For example, we can assemble a... In the view layer DO, You can also VO From the persistence layer , Therefore, the division method associated with business layering seems somewhat redundant . The understanding abstracted from the project code is :VO Corresponding to the data to be displayed on the page ,DO Corresponding to the data stored in the database ,DTO Corresponds to data that needs to be passed in addition to both .
PO(persistant object) Persistent object
stay o/r The concept that appears when mapping , without o/r mapping , There is no such concept . It usually corresponds to the data model ( database ), It also has some business logic processing . It can be seen as mapping to tables in the database java object . The simplest PO It is a record in a table corresponding to the database , Multiple records can be used PO Set . PO There should be no database operations in the .
DO(Domain Object) Domain object
A tangible or intangible business entity abstracted from the real world .
TO(Transfer Object) , Data transmission object
Different in applications tie( Relationship ) Between objects
DTO(Data Transfer Object) Data transmission object
This concept comes from J2EE Design mode of , The original purpose was to EJB Distributed applications provide coarse-grained data entities , To reduce the number of distributed calls , This improves the performance of distributed calls and reduces network load , But here, , I refer generally to the data transfer objects used between the presentation layer and the service layer .
VO(value object) The value object
It is usually used for data transfer between business layers , and PO It's just data . But it should be an abstract business object , It can correspond to a table , Or not , It depends on the needs of the business . use new Keyword creation , from GC The recycling .
BO(business object) The business object
From a business model perspective , see UML Domain objects in component domain model . Encapsulating business logic java object , By calling DAO Method , combination PO,VO Conduct business operations . business object: The business object The main function is to encapsulate the business logic as an object . This object can include one or more other objects . Like a resume , Have educational experience 、 Work experience 、 Social relations and so on . We can match educational experience with PO , Work experience corresponds to a PO , Social relations correspond to one PO . Create a resume for BO Object processing resume , Every BO Contains the PO . When doing business logic like this , We can aim at BO To deal with .
POJO(plain ordinary java object) Simple and irregular java object
In a purely traditional sense java object . That is to say, in some Object/Relation Mapping In the tools , Be able to maintain database table records persisent object It's exactly a match for Java Bean Normative purity Java object , No other attributes or methods have been added . My understanding is the most basic Java Bean , Only attribute fields and setter and getter Method !.
DAO(data access object) Data access object
It's a sun A standard of j2ee Design patterns , There is an interface in this pattern that is DAO , It negates the operation of persistence layer . Provide interfaces for the business layer . This object is used to access the database . Usually and PO Use a combination of , DAO Contains a variety of database operations . By its way , combination PO Related operations on the database . Sandwiched between business logic and database resources . coordination VO, Providing the database CRUD operation .
边栏推荐
- 聊聊面试必问的索引
- 【剑指offer】面试题50:第一个只出现一次的字符——哈希表查找
- Network principle (1) - overview of basic principles
- Troubleshooting the slow startup of spark local programs
- C语言:函数栈帧
- On juicefs
- 【云享读书会第13期】FFmpeg 查看媒体信息和处理音视频文件的常用方法
- [Yunxiang book club issue 13] common methods of viewing media information and processing audio and video files in ffmpeg
- Modify spark to support remote access to OSS files
- “router-link”各种属性解释
猜你喜欢

C language: data storage

What format is this data returned from the background

C language: custom type

Summer Challenge harmonyos realizes a hand-painted board

Network principle (1) - overview of basic principles

flutter —— 布局原理与约束

Network principle (2) -- network development

C language: function stack frame

Hyperlink parsing in MD: parsing `this$ Set() `, ` $` should be preceded by a space or escape character`\`

On juicefs
随机推荐
go语言慢速入门——包
First understanding of structure
【剑指offer】面试题56-Ⅰ:数组中数字出现的次数Ⅰ
/Dev/loop1 takes up 100% of the problem
JS find the maximum and minimum values in the array (math.max() method)
go语言慢速入门——基本内置类型
Spark 3.0 测试与使用
实现自定义Spark优化规则
低代码是开发的未来吗?浅谈低代码平台
Is low code the future of development? On low code platform
JS uses extension operators (...) to simplify code and simplify array merging
CAS compares the knowledge exchanged, ABA problems, and the process of lock upgrading
js使用for in和for of来简化普通for循环
js操作dom节点
Read the wheelevent in one article
网络设备硬核技术内幕 路由器篇 22
[正则表达式] 匹配分组
md 中超链接的解析问题:解析`this.$set()`,`$`前要加空格或转义符 `\`
直接插入排序
Spark RPC