I've got a User domain object class, and a UserDAO class. The User only cares about it's state, and UserDAO only about the data storage. From what I've read, they should not know nor care about each other.
I then wondered how I could use my User class to do things with UserDAO and vice versa. After some research I found out about Service classes, that they're supposed to couple a bunch of related classes together for interaction User and UserDAO in my case).
If DAOs aren't supposed to know nor care about domain objects why have I seen some DAOs that accept their corresponding domain object as an argument or even return it?
class UserDAO
{
//other logic
public function fetchById($id)
{
//user fetch logic
return new User(...);
}
public function persist(User $user)
{
//user persist logic
}
//other logic
}
What would be the correct way of handling this? With the above UserDAO is clearly aware of User.