Hi there! Is it ok to have one of my DAOs depending on another one? This happens because of a composition in my Tables.
I have a DAO for users and one for Projects, but projects have users so I have something like this:
public class userDAO{
findUser(id)
}
public class projectDAO{
findProject(id){
project.addUser(userDao.find(userID));
}
is it ok, or am I breaking some pattern rule here?
-
DAO: is it ok to have a DAO depending on another? (4 messages)
- Posted by: Vinicius Carvalho
- Posted on: October 13 2004 12:39 EDT
Threaded Messages (4)
- Why Not by Darryl Smith on October 13 2004 13:00 EDT
- Why Not by Vinicius Carvalho on October 13 2004 13:35 EDT
- Manager? by Adam Jordens on October 16 2004 02:01 EDT
- Why Not by Vinicius Carvalho on October 13 2004 13:35 EDT
- DAO: is it ok to have a DAO depending on another? by Guy Pardon on October 16 2004 03:56 EDT
-
Why Not[ Go to top ]
- Posted by: Darryl Smith
- Posted on: October 13 2004 13:00 EDT
- in response to Vinicius Carvalho
Why not
public class projectDAO{
findProject(id,<whatever_userDAO_returns>){
call to projectDAO
}
? -
Why Not[ Go to top ]
- Posted by: Vinicius Carvalho
- Posted on: October 13 2004 13:35 EDT
- in response to Darryl Smith
Cuz I don't wanna bother my clients to know about the other dao (although some other clients use it) That's why, I'd like to make it clear for the client. It only calls one DAO, the DAO it self resolves it dependencies. -
Manager?[ Go to top ]
- Posted by: Adam Jordens
- Posted on: October 16 2004 02:01 EDT
- in response to Vinicius Carvalho
Cuz I don't wanna bother my clients to know about the other dao (although some other clients use it) That's why, I'd like to make it clear for the client. It only calls one DAO, the DAO it self resolves it dependencies.
What I've done in a situation like this is use a manager to serve as the outtermost point of contact. In your case, I guess you would have a Project manager which would contain references to the ProjectDAO & UserDAO. With Spring you can just inject the different DAO's that are required by and let the manager handle any inter-dao business logic. Your saveProject() logic in the Manager could do the neccessary operations on the project dao and then do operations using the user dao.
I like to treat my DAO's as trivial db interactions, add remove update query, and let the managers build on the exposed functionality. -
DAO: is it ok to have a DAO depending on another?[ Go to top ]
- Posted by: Guy Pardon
- Posted on: October 16 2004 03:56 EDT
- in response to Vinicius Carvalho
Hi,
In my experience it is best _not_ to let DAOs depend on each other.
For instance, consider the case of integration between different databases, where different DAOs are for different databases. If you mask the DAO from the client application then you have to implement all referential integrity rules in the DAO itself.
But the referential integrity can be seen as business logic, not so much database-specific. By implementing it outside the DAO, you can reuse the same logic across different databases and DAOs.
Another reason is the complexity of your value objects. If you mix DAO implementations with one another then it is also easy to end up with many dependencies between your value object classes. In my experience this leads to messy design and code.
Hope that helps,
Guy
Java Transaction Processing SoftwareHi there! Is it ok to have one of my DAOs depending on another one? This happens because of a composition in my Tables.I have a DAO for users and one for Projects, but projects have users so I have something like this:public class userDAO{findUser(id)}public class projectDAO{findProject(id){project.addUser(userDao.find(userID));}is it ok, or am I breaking some pattern rule here?