DAO Pattern

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

DAO Pattern

Post by The_Nick »

Hi,
Reading from this oracle article about the DAO Pattern: http://www.oracle.com/technetwork/java/ ... 38824.html
Here is the point where they describe the participants (or actors)of the pattern:
BusinessObject

The BusinessObject represents the data client. It is the object that requires access to the data source to obtain and store data. A BusinessObject may be implemented as a session bean, entity bean, or some other Java object, in addition to a servlet or helper bean that accesses the data source.
DataAccessObject

The DataAccessObject is the primary object of this pattern. The DataAccessObject abstracts the underlying data access implementation for the BusinessObject to enable transparent access to the data source. The BusinessObject also delegates data load and store operations to the DataAccessObject.
DataSource

This represents a data source implementation. A data source could be a database such as an RDBMS, OODBMS, XML repository, flat file system, and so forth. A data source can also be another system (legacy/mainframe), service (B2B service or credit card bureau), or some kind of repository (LDAP).
TransferObject

This represents a Transfer Object used as a data carrier. The DataAccessObject may use a Transfer Object to return data to the client. The DataAccessObject may also receive the data from the client in a Transfer Object to update the data in the data source.
What is exactly a Transfer Object and what is exactly a Business Object? Could you make a real life example to better clarify this doubt?

Thanks a lot in advance!

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Re: DAO Pattern

Post by The_Nick »

Ok I reply myself:
From the very same link:
Example 9.5 Customer Transfer Object

public class Customer implements java.io.Serializable {
// member variables
int CustomerNumber;
String name;
String streetAddress;
String city;
...

// getter and setter methods...
...
}
From that I assume the transfer object is the java bean which encapsule the DAO object by the setters and getters.

The business object: well, I think it's related a way more to J2EE than JSE7, however it could be simplisticly implemented in JSE with a normal java class flow controlling the various transfer objects in order to interact with the database, in other words a way to interact with all the other participants.

Please correct me if I am wrong.

The_Nick.

admin
Site Admin
Posts: 10065
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: DAO Pattern

Post by admin »

Transfer object is a POJO that captures just the data of your entity. It has no business logic i.e. it doesn't understand what that data means and can't do anything with that data. So, it usually just has getters and setters.

Business Object contains the actual business logic of the application. For example, you might have a class named AccountManager, that has a method createAccount that takes an Account object. So createAccount is a business method , Account is a VO/DTO. Futher, AccountManager could use a class named AccountDAO, which knows how to save this Account object to the database.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 212 guests