You want to encapsulate data access and manipulation in a separate
- You want to implement data access mechanisms to access and manipulate
data in a persistent storage.
- You want to decouple the persistent storage implementation from the
rest of your application.
- You want to provide a uniform data access API for a persistent mechanism
to various types of data sources, such as RDBMS, LDAP, OODB, XML repositories,
flat files, and so on.
- You want to organize data access logic and encapsulate proprietary
features to facilitate maintainability and portability.
Use a Data Access Object to abstract and encapsulate
all access to the persistent store. The Data Access Object manages
the connection with the data source to obtain and store data.
- Custom Data Access Object Strategy
- Data Access Object Factory Strategies
- Transfer Object Collection Strategy
- Cached RowSet Strategy
- Read Only RowSet Strategy
- RowSet Wrapper List Strategy
- Centralizes control with loosely coupled handlers
- Enables transparency
- Provides object-oriented view and encapsulates database schemas
- Enables easier migration
- Reduces code complexity in clients
- Organizes all data access code into a separate layer
- Adds extra layer
- Needs class hierarchy design (Factory Method Strategies)
- Introduces complexity to enable object-oriented design (RowSet Wrapper
- Transfer Object
Data access objects in their most basic form use transfer objects to
transport data to and from their clients. Transfer Object are used in
other strategies of Data Access Objects. The RowSet Wrapper List strategy
returns a list as a transfer object.
- Factory Method [GoF]
and Abstract Factory [GoF]
The Data Access Object Factory strategies use the Factory Method pattern
to implement the concrete factories and its products (DAOs). For added
flexibility, the Abstract Factory pattern is used as described in the
Data Access Object Factory strategy.
- Broker [POSA1]
The DAO pattern is related to the Broker pattern, which describes approaches
for decoupling clients and servers in distributed systems. The DAO pattern
more specifically applies this pattern to decoupling the resource tier
from clients in another tier, such as the business or presentation tier.
- Transfer Object Assembler
The Transfer Object Assembler uses the Data Access Object to obtain
data to build the composite transfer object it needs to assemble and
send as the model data to the client.
- Value List Handler
The value list handler needs a list of results to act upon. Such a list
is often obtained using a Data Access Object, which can return a set
of results. While the value list handler has an option of obtaining
a RowSet from the Data Access Object, it might be better to obtain and
use a RowSet Wrapper List instead.
- CodeFutures adopts and implements the DAO Pattern in their Firestorm DAO product. Check out their product here.