Posted By:
Matan_Amir
Posted On:
Thursday, July 24, 2003 01:35 AM
Hi Guru,
You are right in saying both DAO and datasource objects can achieve the same outcome (data de-coupling) but I think DAO objects are used to provide the data independence in an object oriented manner. If you have DAO objects for specific data sources that inherit from the same interface for example, they can be changed on the fly, or new DAO implementations can be added easily (the factory pattern comes to mind). Like an OracleUserDAO, XMLUserDAO, MySqlUserDAO, 3rdPartyAppUserDAO, etc. all inheriting from IUserDAO.
You are also free to implement each DAO implementation differently and don't need to rely on a datasource object - let's say for file system access.
The question of when to use DAO and when to use entity beans is a tough one. I personally use DAO objects when I don't plan to use EJB at all. I find it a useful pattern, especially when i know the data layer will only be accessed locally (no remote interfaces) and I don't need container managed data persistance.
Hope that helps,
Matan