THE QUESTION:

Does it (make sense|is it general practice) to call one DAO from
within another DAO?

I was hoping that someone on this list could help me free myself
from the shackles of confusion.  At my job, I am developing a web
application using JDBC (required unfortunately) to abstract the data
access but I am running into a problem, one I realize would be
solved by Hibernate, but interesting to attempt to tackle anyway.

Assume I have two entities in my system (amoungst many others),
Contacts and Customers.  Contacts are the end user, and the
customers are the accounts (think of it like online banking).  The
contacts can manipulate these customer accounts by ordering,
viewing, requesting service.

Naturally I made a ContactDAO which retrieves contacts, profile
information, etc.  My next object is CustomerDAO which retrieves
information about the customer (the agency name, mailing address,
etc).  A contact can be associated with many customers and vice
versa, each relationship represented by a role.  Naturally I created
a CustomerContact object which links these two entities:

 +----------------+
 | CustomerContact|
 + ---------------+
 | roleName       |
 | contact        |
 | customer       |
 +----------------+

Here comes my problem.  My ContactDAO takes care of the data access
to the contact table.  The CustomerDAO however contains methods
which must get at the contact data with queries such as
getContactsForCustomer and getCustomersForContact which return
CustomerContact[] arrays (since the ContactDAO shouldn't have
methods dealing with the customer relationship since it is not a
dependency of a contact, but is of a customer).  In my CustomerDAO,
to create the CustomerContact transfer object, I need to talk to my
ContactDAO to get that information, if I don't want to duplicate the
calls in the CustomerDAO.

In short, at some point, one DAO needs to use the methods in the
other DAO since there is cross over.  The main confusion here is how
to deal with information that seems to want to be in both DAOs.

THE QUESTION:

Does it (make sense|is it general practice) to call one DAO from
within another DAO?

Thanks,

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <[EMAIL PROTECTED]>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Microsoft's Law of Software Engineering: 
Don't worry if it doesn't work right. 
If everything did, we'd be out of a job.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
Struts-apps mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/struts-apps

Reply via email to