I'm trying to apply the principles of the DAO from the J2EE book in a
project I'm working on right now.
Basically....
* I have a Person class. A Person can have one or more Addresses.
* I have a User class, which contains a Person class and adds stuff for
login, roles, etc.
* I have an Order class, which has Shipments, which each contain a Person,
an Address and a Shipper, etc.
Simple stuff I know.
What I'm uncertain of is the design of the database/persistence tier. The
the Data Access Object pattern (p 462) is used for saving business
objects. The example shows a the DAOFactory which implements methods to
create a CustomerDAO and an EmployeeDAO.
In the examples, these two objects have no relationship. So it seems
reasonable to separate the two. But it left me wondering how to handle
composite objects (like User which as a Person) leaves me a little unsure
about the right design approach:
* I can write one DAO for all classes with methods like updatePerson,
updateAddress, etc., and then composite objects can call all the methods
necessary to save themselves and their children. DAO's seem a bit like the
Bridge pattern (GoF) to me. And this seems like a Bridge-style
implementation, except instead of the drawing methods given as examples in
the GoF book, I've got db methods. This doesn't seem like a crazy idea.
* I can write one DAO for each class, but DAO's for composite classes will
effectively be composite DAO's. In other words, UserDAO would contain a
PersonDAO just like User contains a Person. DAOFactory needs to know how to
build the composite DAOs and so needs to be a bit smart about how the
composite POJOs are constructed. Alternatively (or even in addition), each
DAO could get a reference to the factory that created it and ask for
contained DAOs as necessary. Doesn't seem crazy to me, but does require a
bit of coordination across the objects.
* There might be some way that the UserDAO is simply a decorator for the
PersonDAO.
Any feedback?
Thanks
Scott
====================================================================
Companion Site: http://www.corej2eepatterns.com
J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns
List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html
Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)