b.Data Transfer Object (DTO) Pattern

  1. Motivation
    1. T Create an object that carries data between processes in order to reduce the number of method calls.
  2. Summary
    1. When you're working with a remote interface, such as Remote Facade, each call to it is expensive. As a result you need to reduce the number of calls, and that means that you need to transfer more data with each call. One way to do this is to use lots of parameters. 
    2. However, this is often awkward to program—indeed, it's often impossible with languages such as Java that return only a single value.
    3. Data Transfer Object is also usually responsible for serializing itself into some format that will go over the wire.
    4. Usually a separate assembler object responsible for creating a Data Transfer Object from the domain model and updating the model from it.
    5. The assembler is an example of a Mapper in that it maps between the Data Transfer Object and the domain objects
    6.  DTO Class Diagram  Reducing the number of calls by using a DTO

  3. When to Use
    1. Use a Data Transfer Object whenever you need to transfer multiple items of data between two processes in a single method call.
  4. Implementation
    1. Create a data transfer object (DTO) that holds all data that is required for the remote call. 
    2. Modify the remote method signature to accept the DTO as the single parameter and to return a single DTO parameter to the client.
    3. After the calling application receives the DTO and stores it as a local object, the application can make a series of individual procedure calls to the DTO without incurring the overhead of remote calls.
  5. Example 
    1. ADO.Net RecordSet 
    2. Dot.Net Collection Objects
  6. Related Patterns
    1. Remote Facade. The Data Transfer Object pattern is typically used in conjunction with a coarse-grained Remote Facade to reduce the number of remote calls.
    2. Mapper. A Mapper is the recommended technique to load the DTO with data elements from the domain objects.
    3. Value Object. Some books refer to Data Transfer Object as Value Object. This usage is no longer considered correct but value object are different that DTO
  7. Related Technologies 
    1. ADO.Net RecordSet 
    2. Dot.Net Collection Objects
  8. References
    1. MSDN : DTO Tutorial
    2. MSDN:Implementing Data Transfer Object in .NET with a DataSet
    3. MSDN: Implementing Data Transfer Object in .NET with a Typed DataSet