DTO vs. VO vs. BO vs. EJB? [closed]

-3

Seeing some example of internet I saw that there are applications where they make a separation of layers from when a request is made until when it is persite in a DB? Is there a real definition of these terms? since I have seen that each user gives a different approach mainly between if it is the same VO and DTO or if an EJB would be considered a BO?.

    
asked by Rene Garnica 20.11.2018 в 23:18
source

1 answer

2

VO: Means Value Object and is a Java Bean object focused on the view. Basically it is a POJO (Plain old java object).

BO: Means Business Object and are generally Java Beans that are mapped to database entities (Business Objects) as for example in Hibernate.

Generally BO is used in a patrón DAO (Data Access Object) built on a patrón ORM (Object-Relational mapping) to indicate that the BO classes that contain the business logic (access to the BD). These BO classes, if they can be accessed when published in an API, would generate a lot of insecurity as they provide access to the database. Therefore, BO classes are usually copied into VO classes where VOs no longer have direct access to the BD and can be exposed in public APIs without generating security failures.

DTO: Means Data Transfer Object 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 manages events configured by annotations or by XML. If the EJB manages access to the database, it could be called BO if it follows the corresponding design pattern. Los EJBs son una API completa that is the competence of other frameworks, for example spring .

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:

@Transactional(readOnly = true)
    public ArrayList<BancoDTO> listar() throws Exception {
        System.out.println("llegue a banco service");

        ArrayList<Banco> bancos = bancoDAO.getAll();
        ArrayList<BancoDTO> listaDTO = new ArrayList<BancoDTO>();
        for (Banco banco : bancos) {
            System.out.println(banco.getIdBanco()+" - "+banco.getNombre());
            BancoDTO bancoDTO = new BancoDTO();
            bancoDTO.setIdBanco(banco.getIdBanco());
            bancoDTO.setNombre(banco.getNombre());
            listaDTO.add(bancoDTO);
        }

        return listaDTO;
    }

The bancoDAO object is the object that accesses a database entity (a table). Since it is a select operation ( bancoDAO.getAll() ) the entire method is written with a read-only transaction ( @Transactional(readOnly = true) ). This method belongs to a web Service System.out.println("llegue a banco service"); , so the bancoDAO object is not publicly exposed, but copied to a DTO ( BancoDTO bancoDTO = new BancoDTO(); ) and this object is the one that is publicly exposed.

At the end of the day all these are conventions (like that of the setters and getters) but several frameworks follow them and nothing forces you to use them but if you use any framework that follows them and you do not, it could not work what you do in said framework.

    
answered by 21.11.2018 / 01:51
source