need of DAO factory

Hi

I was reading about DAO patterns in various threads here and some examples of the implementation.

There is one thing I am not clear with, is the use of DAO factory.

why can't we do

daoObj = new DAOClass() ; wherever we want to use it instead of the factory method returning the same

TIA

[329 byte] By [am_newa] at [2007-10-2 12:11:44]
# 1

> Hi

>

> I was reading about DAO patterns in various threads

> here and some examples of the implementation.

>

> There is one thing I am not clear with, is the use of

> DAO factory.

>

> why can't we do

> daoObj = new DAOClass() ; wherever we want to use it

> instead of the factory method returning the same

>

> TIA

you can, but you tie your business objects to the persistence mechanism you're using (IOW : the DAO class).

for a quite comprehensive discussion about its benefits :

[url=http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html]Data Access Objects[/url]

Torajiroua at 2007-7-13 8:54:21 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
So factory is going to be useful if persistence is supposed to change right?If not it will add another layer !correct me if am wrong
am_newa at 2007-7-13 8:54:21 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
Spring is really good for this. You declare the DAO in your Spring XML configuration and give it a SessionFactory through dependency injection. Then you can use the WebApplicationContext to return an instance of the DAO when required.
YoGeea at 2007-7-13 8:54:21 > top of Java-index,Other Topics,Patterns & OO Design...