Looking at some examples on the internet, I saw that there are applications where they make a separation of layers from when a request is made to when it is persisted in a DB? Is there a real definition of these terms? Since I have seen that each user gives a different approach, mainly if it is the same VO and DTO or if an EJB would be considered a BO?
VO: Stands
Value Object
for and is a view-focused Java Bean object. It's basically aPOJO (Plain old java object).
BO: Means
Business Object
and is generally the Java Beans that are mapped to database entities (Business Objects) such as in Hibernate.BOs are generally used in a
patrón DAO (Data Access Object)
built-onpatrón ORM (Object-Relational mapping)
to point to the BO classes that contain the business logic (database access). These BO classes, if they can be accessed when published in an API, would generate a lot of insecurity since they provide access to the database. For this reason, BO classes are generally copied into VO classes where the VOs no longer have direct access to the DB and can be exposed in public APIs without generating security flaws.DTO: It stands
Data Transfer Object
for A data transfer object is an object that transports data between processes. The motivation for its use is that communication between processes is usually done using remote interfaces (for example, web services), where each call is an expensive operation.A
EJB (Enterprise Java Bean)
is a java bean that handles events configured via annotations or via XML. If the EJB manages database access, it could be called BO if it follows the corresponding design pattern.Los EJBs son una API completa
which is the competition of other frameworks, for examplespring
.I do not master the concepts very well but on this page you can find a better explanation: Design patterns in java mvc dao and dto
The following code is an example:
The bankDAO object is the object that accesses a database entity (a table). Since this is a select (
bancoDAO.getAll()
) operation, the entire method is annotated with a read-only transaction(@Transactional(readOnly = true)
). This method belongs to a web ServiceSystem.out.println("llegue a banco service");
, so the bankDAO object is not exposed publicly, but rather it is copied to a DTO (BancoDTO bancoDTO = new BancoDTO();
) and this object is the one exposed publicly.At the end of the day, these are all conventions (such as setters and getters) but several frameworks follow them and nothing forces you to use them, but if you use a framework that follows them and you don't, what you do in said framework might not work for you.