PO / VO / BO / DTO / POJO / DAO

1. Basic introduction

       PO (persistant object) Persistent object: a concept that appears when o/r mapping, usually corresponds to the data model (database), and itself has some business logic processing. It can be regarded as a java object mapped to the table in the database . The simplest PO is a record corresponding to a table in the database. Multiple records can use a collection of PO. PO should not contain any operations on the database.
       VO (value object) Value object: usually used in the business layer The data transfer between them, like PO, only contains data. But it should be an abstract business object, which can correspond to a table or not, depending on the needs of the business.
       BO (business object) Business object: from the business model From the point of view, the java object that encapsulates the business logic, by calling the DAO method, combined with PO, VO to perform business operations.
       DTO (Data Transfer Object) data transfer object: mainly used for remote calls and other places that require a large number of transfer objects.
For example, if our table has 100 fields, then the corresponding PO has 100 attributes. However, we only need to display 10 fields on the interface, and the client uses WEB service to obtain data. There is no need to pass the entire PO object to the client.
At this time, we can use the DTO with only these 10 attributes to pass the result to the client. This will not expose the server-side table structure. After reaching the client, if this object is used to correspond to the interface display, then its identity will be changed to VO
       POJO (plain ordinary java object), a simple and irregular java object, the most basic Java Bean, only property fields and setter and getter methods!.
      DAO (data access object) data access object is a standard j2ee design pattern of sun. One interface in this pattern is DAO, which is responsible for the operation of the persistence layer. It provides an interface for the business layer. This object is used to access the database. Usually and Used in combination with PO, DAO contains various database operation methods. Through its methods, combined with PO to perform related operations on the database. It is sandwiched between business logic and database resources. With VO, it provides database CRUD operations.

2. Aided comprehension

      PO DTO VO BO are all POJOs, which are simple java objects; DAO is the class for adding, deleting, modifying and checking the database.
      The following focuses on these, they are all POJO
      PO persistent objects, data;
      BO business objects, encapsulated objects, complex objects, which may contain multiple classes;
      DTO transmission objects, which are transmitted during front-end calls;
      VO performance objects, front-end interface exhibit.

      When your business is simple enough, a POJO can be regarded as a PO BO DTO VO. The following is an example: For
      example, there is a user class with only name and phone
      . For the database level, there are only two columns. these two.

      Then talk about the examples of their distinction:
      (1) Or the user class name phone adds a password.
      Then the PO attributes of your backend are also these three. Generally, there are several fields in this table in the database, and your PO has as many attributes. However, when transmitting to the front desk or displaying, we should not pass the password together. So their DTO VO is still name + phone
      po : name phone password
      dto : name phone
      vo : name phone

     (2) Now an enumerated status bit status has been added to indicate some special status of the user, which will not be displayed directly in the foreground, and subsequent operations may be generated according to this status,
      po : name phone password status
      dto : name phone status
      vo : name phone

     (3) Next, look at BO, a user will definitely be associated with many other tables,
      such as user settings user information, etc., then this BO not only has some attributes of the user itself, but also contains two categories of user settings and user information.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325333857&siteId=291194637