Data access object design pattern

This is another very important design pattern. Before you learn about this design pattern, it is better to understand the following points. 

What is DAL (Data Access Layer)?
        • The simple data access layer is used to handle database access in applications.
        • In Layered Architecture, it is a best practice to use a separate layer for data access.
        • The data access layer is being used to achieve this.
        • DAO design pattern and Repository design pattern can be used to implement that Data access layer.

        What is the DAO (Data Access Object)?
        • Usually, this is used to connect both the service layer and database layer as I mentioned above.
        • The main purpose of using DAO is to hide implementation, data with the usage of interfaces.
        • Normally we define DAOs for each and every entity. Eg:
        • DAOs return data as an object state.

        What is the DTO (Data Transfer Object)?
        • Simply this can be a JSON object that can be used to get request data and send response data. 
        • If you design APIs, JSON objects are being used as request and response objects. Eg:,

        Look at the following UML diagram to understand the way of using DAO design pattern. 

        Advantages of using DAO 

        • Hide implementation data.
        • Reduce code complexity.
        • Centralized data access to separate layer called Data Access Layer.

        Disadvantages of DAO

        • This is not the smartest way to achieve those advantages, if you are using a framework like Spring with Spring Data JPA, it can simplify everything than using DAO.

        Data access object design pattern Data access object design pattern Reviewed by Ravi Yasas on 2:52 PM Rating: 5

        No comments:

        Powered by Blogger.