DAO implementation question

I am using most of the pattern from

the core j2eepattern for the DAO factory and I have a question on what would be best. I have the daofactory and the concrete daofactory, for only one db now, then I have classes and a dao for each class. Example I have a class Person which has its own dao the Person's getters and setter interact with. My client code only uses the object and I don't talk to the dao directly except from its matching object.

OK anyways in the client code in the example

...

// create the required DAO Factory

DAOFactory cloudscapeFactory =

DAOFactory.getDAOFactory(DAOFactory.DAOCLOUDSCAPE);

// Create a DAO

CustomerDAO custDAO =

cloudscapeFactory.getCustomerDAO();

I don't want the DAOFactory.DAOCLOUDSCAPE on every object I have. I would like to decouple that away. What would you guys suggest. There are some very easy ways I think to do that I just want to make sure I don't miss anything and end up sorry later :-)

[1077 byte] By [LORDs_diakonosa] at [2007-10-2 0:00:30]
# 1

My experience is that databases don't change that often. I wouldn't worry about a DAO factory for each database. You might have a set of DAOs that will work with one database and another for a second, but they'll all be used together at the same time, right? Or are some DAOs connecting to one database and the others to the second?

If you're writing JDBC that is not specific to a particular database, there's no change in the implementation anyway. The DAO shouldn't have database-specific code in it. The operation of the DAO shouldn't change.

I'd have a DAO interface with CRUD operations and an implementation that will work with a particular database. Changing the database would mean changing the implementation.

All this should be configured external to the app.

If you're using Spring and Hibernate, it's a lot easier. Why write all that stuff yourself?

%

duffymoa at 2007-7-15 15:54:42 > top of Java-index,Other Topics,Patterns & OO Design...