Data access object

From Wikipedia, the free encyclopedia
  (Redirected from Data Access Object)
Jump to: navigation, search
This article is about the software design pattern. For the Microsoft library, see Jet Data Access Objects.

In computer software, a data access object (DAO) is an object that provides an abstract interface to some type of database or other persistence mechanism. By mapping application calls to the persistence layer, DAO provide some specific data operations without exposing details of the database. This isolation supports the Single responsibility principle. It separates what data accesses the application needs, in terms of domain-specific objects and data types (the public interface of the DAO), from how these needs can be satisfied with a specific DBMS, database schema, etc. (the implementation of the DAO).

Although this design pattern is equally applicable to most programming languages, most types of software with persistence needs, and most types of databases, it is traditionally associated with Java EE applications and with relational databases accessed via the JDBC API because of its origin in Sun Microsystems' best practice guidelines[1] ("Core J2EE Patterns") for that platform.


The advantage of using data access objects is the relatively simple and rigorous separation between two important parts of an application that can and should know almost nothing of each other, and which can be expected to evolve frequently and independently. Changing business logic can rely on the same DAO interface, while changes to persistence logic do not affect DAO clients as long as the interface remains correctly implemented.

  • hide all details of data storage from the rest of the application.
  • act as an intermediary between the application and the database. They move data back and forth between objects and database records.
  • allow ripple effects from possible changes to the persistence mechanism to be confined to a specific area.

In the non specific context of the Java programming language, Data Access Objects as a design concept can be implemented in a number of ways. This can range from a fairly simple interface that separates the data access parts from the application logic, to frameworks and commercial products. DAO coding paradigms can require some skill. Use of technologies like Java persistence technologies and JDO ensures to some extent that the design pattern is implemented. Technologies like Enterprise JavaBeans come built into application servers and can be used in applications that use a JEE application server. Commercial products like TopLink are available based on Object-relational mapping (ORM). Popular open source ORM products include Doctrine, Hibernate, iBATIS and Apache OpenJPA.


Potential disadvantages of using DAOs include leaky abstraction[citation needed], code duplication,[2] and abstraction inversion. In particular, the abstraction of the DAO as a regular Java object can hide the high cost of each database access, and can also force developers to trigger multiple database queries to retrieve information that could otherwise be returned in a single operation with normal SQL set operations.

Tools and frameworks[edit]

See also[edit]


  1. ^ "Core J2EE Patterns - Data Access Objects". Sun Microsystems Inc. 2007-08-02. 
  2. ^ See for workarounds

External links[edit]