Name

Data Access Object

Goal

Separate code for accessing data from a persistence mechanism from code used for processing data (Figure B-4).

Data access object
Figure B-4. Data access object

Participants

Business object/presentation object

Implements business logic for an application.

Data access object (DAO)

Provides access to the persistence layer via a Java interface.

Data object

Represents the data in the persistence layer as a Java object.

Persistence mechanism

Provides a method for saving and restoring application data.

Interactions

A business object or presentation tier object obtains an instance of a data access object (DAO), which it uses to save and retrieve data objects. The DAO is responsible for all interactions with the persistence mechanism (database, raw files, etc.) used to store the application data. A data object independent from the persistence layer (see the Data Transfer Object pattern) is used to exchange data between the business objects and the DAO.

Get J2EE Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.