Update README.md
This commit is contained in:
parent
6373f7b115
commit
8512c65aef
@ -9,13 +9,16 @@ tags:
|
|||||||
---
|
---
|
||||||
|
|
||||||
## Intent
|
## Intent
|
||||||
Pass data with multiple attributes in one shot from client to server, to avoid multiple calls to remote server.
|
|
||||||
|
Pass data with multiple attributes in one shot from client to server, to avoid multiple calls to
|
||||||
|
remote server.
|
||||||
|
|
||||||
## Explanation
|
## Explanation
|
||||||
|
|
||||||
Real world example
|
Real world example
|
||||||
|
|
||||||
> We need to fetch information about customers from remote database. Instead of querying the attributes one at a time, we use DTOs to transfer all the relevant attributes in a single shot.
|
> We need to fetch information about customers from remote database. Instead of querying the
|
||||||
|
> attributes one at a time, we use DTOs to transfer all the relevant attributes in a single shot.
|
||||||
|
|
||||||
In plain words
|
In plain words
|
||||||
|
|
||||||
@ -23,16 +26,17 @@ In plain words
|
|||||||
|
|
||||||
Wikipedia says
|
Wikipedia says
|
||||||
|
|
||||||
> In the field of programming a data transfer object (DTO) is an object that carries data between processes. The
|
> In the field of programming a data transfer object (DTO) is an object that carries data between
|
||||||
motivation for its use is that communication between processes is usually done resorting to remote interfaces
|
> processes. The motivation for its use is that communication between processes is usually done
|
||||||
(e.g., web services), where each call is an expensive operation. Because the majority of the cost of each call is
|
> resorting to remote interfaces (e.g. web services), where each call is an expensive operation.
|
||||||
related to the round-trip time between the client and the server, one way of reducing the number of calls is to use an
|
> Because the majority of the cost of each call is related to the round-trip time between the client
|
||||||
object (the DTO) that aggregates the data that would have been transferred by the several calls, but that is served by
|
> and the server, one way of reducing the number of calls is to use an object (the DTO) that
|
||||||
one call only.
|
> aggregates the data that would have been transferred by the several calls, but that is served by
|
||||||
|
> one call only.
|
||||||
|
|
||||||
**Programmatic Example**
|
**Programmatic Example**
|
||||||
|
|
||||||
Let's first introduce our simple customer DTO class.
|
Let's first introduce our simple `CustomerDTO` class.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
public class CustomerDto {
|
public class CustomerDto {
|
||||||
@ -60,7 +64,7 @@ public class CustomerDto {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Customer resource class acts as the server for customer information.
|
`CustomerResource` class acts as the server for customer information.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
public class CustomerResource {
|
public class CustomerResource {
|
||||||
@ -94,10 +98,12 @@ Now fetching customer information is easy since we have the DTOs.
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Class diagram
|
## Class diagram
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Applicability
|
## Applicability
|
||||||
Use the Data Transfer Object pattern when
|
|
||||||
|
Use the Data Transfer Object pattern when:
|
||||||
|
|
||||||
* The client is asking for multiple information. And the information is related.
|
* The client is asking for multiple information. And the information is related.
|
||||||
* When you want to boost the performance to get resources.
|
* When you want to boost the performance to get resources.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user