Thursday, January 15, 2015

DTO and DAO

You may have seen in some Java codes there are Java class names end with ...DTO and ...DAO. Why do we need this practice?

First of all let's look at what they stand for?

DTO : Data Transfer Object
DAO : Data Access Object

DTO objects are used to transfer data between classes and modules of an application. DTO consists of only private fields, getters, setters and constructors. It is not recommended to add business logic methods to such classes. But they may contain some util methods. 

DAO classes encapsulate the logic for retrieving, saving and updating data in some data source or storage (a database, a file-system, etc.).
They abstract and encapsulate all access to the data source. The DAO manages the connection with the data source to obtain and store data.

Here is a good explanation about the DAO pattern.

No comments: