[Poeaa] learning notes of data transfer object

Source: Internet
Author: User
Tags to domain

The data transfer object is the object used to transmit data.

 

In a process, method calls are very fast, but the calls between different processes are much slower, especially in distributed applications.ProgramIn, remote process calls are very time-consuming. To improve efficiency, we want to transmit as much data as possible in each call (if it is called frequently, each call only transmits a small amount of data, for example, the first call to obtain an articleArticleName of the author, the second call to obtain the city where the author is located, the overhead is very large ).

 

As mentioned in the msdn article:

In modern IP routing-based networks (for example, the Internet), latency can be a bigger factor than throughput. that means it may take almost the same amount of time to transmit 10 bytes of data as it takes to transmit 1,000 bytes of data. this effect is particle ly pronounced when using connectionless protocols such as HTTP.Faster networks can often increase the throughput (throughput), but latency (latency) is much more difficult to reduce.

 

We can also see that even if we transmit a small amount of data each time, the efficiency will not be much improved.

 

In order to transmit more data in one call, We can naturally think of passing many parameters, but imagine that if we pass 10 string parameters to the remote process, it is very likely that errors will occur (for example, the second and third parameters are reversed during programming), and if multiple parameters are returned, it is even more impossible.

 

So data transfer object (DTO) appeared. It extracts all the method parameters mentioned above as its own value range and sets getter and setter for them. This is DTO, which is a simple data structure with no program logic, its task is to allow remote calls to transmit more data at a time in a more convenient way. For example, in the previous scenario, you can place the title, author name, and author's city in DTO and set getter and setter respectively.

 

Dto's value range is a simple type, because it should be easy for both the client and server to understand them, and DTO should not contain many business logic, it is used to transmit data during Remote calls.

 

Dto's value ranges generally come from multiple domain objects. For example, in the previous scenario, the value range of DTO comes from the article class and author class.

 

DTO is generally designed for special client purposes. For example, the content displayed on a webpage, a GUI, this makes it possible to design a large number of DTO for remote calls when remote calls are frequent but not all call the same method. At the same time, it also consumes effort to write these DTO (of course, you can also useCodeGenerate tools ).

 

We should not allow domain objects to depend on DTO or add a lot of computing logic to DTO. Therefore, in order to contact DTO and domain objects, there is usually a middleware:

From msdn

 

However, in this case, the aggreger is too dependent on domainobject and DTO. Changes to domain object and DTO will affect the aggreger.

 

References:

1. Martin Fowler: "patterns of enterprise application architecture ";

2. msdn: data transfer object, http://msdn.microsoft.com/en-us/library/ms978717.aspx

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.