Saturday, 27 July 2013
What is the difference between DTO and DAO
DAO is a class that usually has the CRUD operations like save, update, delete. DTO is just an object that holds data. It is JavaBean with instance variables and setter and getters.
A DAO can be thought of as a proxy used by the business tier who is its client to retrieve values from any given resource such as a RDMS, LDAP server, XML repository, OODB, flat files and so forth. Here is how it looks:
your code -> DAO -> JDBC
The DTO, Value Object(VO) is used to expose several values in a bean like fashion. This provides a light-weight mechanism to transfer values over a network or between different application tiers.
DTO will be passed as value object to DAO layer and DAO layer will use this object to persist data using its CRUD operation methods.
The advantage of the DAO layer is that if you need to change the underlying persistence mechanism you only have to change the DAO layer, and not all the places in the domain logic where the DAO layer is used from. The DAO layer usually consists of a smaller set of classes, than the number of domain logic classes that uses it. Should you need to change what happens behind the scene in the DAO layer, the operation is somewhat smaller, since it only affects the DAO layer.
The advantage of DTO layer is that it adds a good deal of flexibility to the service layer and subsequently to the design of the entire application. For example, if DTOs are used, a change in the requirements that forces a move to a different amount of data doesn't have any impact on the service layer or even the domain. You modify the DTO class involved by adding a new property, but leave the overall interface of the service layer intact.

No comments:
Post a Comment