Hi,
Here is a small example where DTO seems to be useful. I would like to have some feedback on how to do this without DTO.
I have a User and Profile classes. One User can have multiple Profile.
Code:
public class User
{
private List listOfProfile;
}
I have a common architecture. A domain layer made of BO (Hibernate independent) + DAO (hibernate dependent). On top of that, I have a service layer made of services that communicates with the presentation layer (Struts like) with DTOs.
To add a Profile to a User I have to check if there is enough licences. In my point of view this check occurs in the service layer.
To modify the User"s profiles I have a service like
Code:
public class UserService
{
public UserDTO getUser(String userID);
public UserDTO modifyUser(UserDTO user);
public UserDTO modifyUserProfiles(UserDTO user);
}
With this service, I can ensure that my presentation layer must go through the 'modifyUserProfiles' method to modify the user profiles (because in the modifyUser method I don't care about any profiles modification).
Now without my DTOs I would have a service like this
Code:
public class UserService
{
public User getUser(String userID);
public User modifyUser(User user);
public User modifyUserProfiles(User user);
}
If I want to add some profiles to a user, in the presentation layer I can do :
Code:
User user = userService.getUser("myId");
user.getListOfProfiles().add(aProfile);
userService.modifyUser(user);
with Hibernate's transitive persistence mechanism, the profile is added to the User without any licence check.
As this is a service level check, I don't want to use any of the Hibernate tricks (interceptors for example) to do that. I want to do it in an Hibernate independent way.
So, is there a way to achieve my goal without the use of DTOs
Thanx, Seb