The DAO design pattern

The DAO design pattern can be used to provide a separation between the low-level data accessing operations and the high-level business services, as shown here:

The DAO design pattern

The DAO layer

In between the database and the business layer, there is a layer called the DAO layer. The DAO layer is mainly used to perform the Create-Retrieve-Update-Delete (CRUD) operation. The DAO layer is responsible for creating, obtaining, updating, or deleting records in the database table. To perform this CRUD operation, DAO uses a low-level API, such as the JDBC API or the Hibernate API. This DAO layer will have a method for performing the CRUD operation. It is the intermediate layer between the Business Layer and the DB. It is used to separate the low-level accessing API from the high-level business service. The DAO layer decouples the implementation of persistent storage from the rest of your application.

The advantages of using DAO are as follows:

  • Its application is independent of the data access techniques and database dependency
  • It offers loose coupling with the other layers of the application
  • It helps the unit test the service layer using a mock object without connecting to the database
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.125.69