Data Access Object Pattern - Design Patterns

What is Data Access Object Pattern?

Data Access Object Pattern or DAO pattern is use to disconnect low level data accessing API or operations from high level business services. Following are the participant in Data Access Object Pattern.

  • Data Access Object Interface - This interface defines the standard operations to be performed on a model object(s).
  • Data Access Object concrete class - This class implements above interface. This class is responsible to get data from a data source which can be database / xml or any other storage mechanism.
  • Model Object or Value Object - This object is simple POJO containing get/set methods to store data retrieved using DAO class.

Implementation

We are going to generate a Student object substitute as a representation or Value Object.StudentDao is Data Access Object Interface.StudentDaoImpl is material class implementing Data Access entity Interface. DaoPatternDemo, our demo class, will use Student Dao to demonstrate the use of Data Access entity pattern.
dao_pattern_uml_diagram

Step 1

Create Value Object.

Student.java

Step 2

Create Data Access Object Interface.

StudentDao.java

Step 3

Create concrete class implementing beyond interface.

StudentDaoImpl.java

Step 4

Use the learner Dao to display Data Access Object pattern usage.

DaoPatternDemo.java

Step 5

Verify the output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Design Patterns Topics