DTO: a final note
This post should close the DTO (or ObjectView) series
In the last post I shown an elegant solution to the DTO implementation using a class that wrap the Domain Model Objects. That solution is, for what I seen, the most used but in this post I would like to show a third possible implementation.
The only little thing of the wrapper solution is that the DTO depend from the Domain Model Oject because internally it has a reference to the Employee class. To remove this dependency we could design a class that contains only the properties to use on the User Interface without the reference to Employee. For example:
   public class EmployeeDTO
   {
       private String _name;
       private String _fullAddress;
      Â
       public String Name
       {
           get { return _name; }
           set { _name = value; }
       }
  Â
       public String FullAddress
       {
           get { return _fullAddress; }
           set { _name = _fullAddress; }
       }
   }
This solution provide a purely container object that has no reference to the Domain Model. But it raise another little problem. Who fill this class with the right data? The service layer is responsible to transform the Domain Objects in these DTOs and a lot of mapping code should be written.
So as usual theres no one best solution, every context has it’s right solution.
Posted in Emanuele DelBono | No commentsNo comments yet. Be the first.
Leave a reply
RSS


