Graduation Project Summary (1) database concepts: DO, DTO, dodto
This time, the project was completed in full accordance with the software engineering process. I felt a lot about it. I did not write a summary. I would like to summarize some technical problems in the process, first, let's talk about several concepts of software design entities.
In fact, there are four concepts in total: VO, DTO, DO, And PO. Based on my own understanding, I only talk about DTO and DO. However, the following is an explanation of the four concepts:
(1) Concepts
VO (View Object): A View Object used to display layers. It encapsulates all data of a specified page (or component.
DTO (Data Transfer Object): Data Transmission Object. This concept comes from the J2EE design mode. The original purpose is to provide coarse-grained Data entities for the Distributed Application of EJB, to reduce the number of distributed calls, so as to improve the performance of distributed calls and reduce network load, but here, I usually refer to the data transmission objects between the presentation layer and the service layer.
DO (Domain Object): A Domain Object is a tangible or intangible business entity abstracted from the real world.
PO (Persistent Object): A Persistent Object, which has a one-to-one ing relationship with the data structure of the Persistent layer (usually relational databases). If the Persistent layer is a relational database, each field (or several) in the data table corresponds to one (or more) attribute of the PO.
(2) DO
DO and Domain Object are usually placed in the Model package, that is, they exist as Object of the project and are often classes that directly interact with the ORM framework.
In actual development, DO is often a POJO. It provides the basic Get/Set Method to facilitate data operations. Generally, the attribute is private, you can access attributes only through the G/S method. It is also DO that interacts directly with the database.
(3) DTO
DTO, Date Transfer Object is literally a data transmission class. In fact, this is also true, the complexity of a required class is often not handled by a database table, but is assembled and combined into a result through multiple queries. For example:
When presenting a Project in the foreground, you may need to provide ProjectName and UserName (Project name, owner name). In the database, the corresponding Project table fields may be ProjectId and UserId. Only the Project table can be queried by a User Id. to query more information about the User, you must join the User table for query, the Project class in DO cannot have such detailed and diversified attributes. The assembled data should be placed in the ProjectDTO class. The sample code is as follows:
1 public class Project{2 private String projectName;3 private String userid; 4 }
1 public class User{2 private String username;3 private String userid;4 }
public class ProjectDTO{ private String projectName; private User user;}
In this way, the ProjectDTO can be uploaded to the front-end page to obtain suitable display data. At the same time, because the example is not perfect, the User in DTO is usually UserDTO in actual applications, because the User class may contain attributes such as Password.