January 8, 2017

DAO and DTO

DTO is an abbreviation for Data "Transfer" Object.

  • It is used to transfer the data between classes and modules of your application, typically with data/values from database. DTO should only contain private fields for your data, getters, setters and constructors. It is not recommended to add any logic methods to such classes.


DAO is an abbreviation for Data "Access" Object.

  • It should have the logic for retrieving, saving and updating data in your database.

Business Object is the class that uses DAO and DTO. Consider this is our servlet. It also has all logics (methods to do stuff etc).





Here is an example how the DAO and DTO interfaces would look like: