什么是数据传输对象? [英] What is Data Transfer Object?

查看:200
本文介绍了什么是数据传输对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是数据传输对象?

在MVC是模型类DTO,如果不是有什么区别?我们都需要?

In MVC are the model classes DTO, and if not what are the differences and do we need both?

推荐答案

一个数据传输对象是用于封装数据,并从一个应用程序中的一个子系统将其发送到另一对象

A Data Transfer Object is an object that is used to encapsulate data, and send it from one subsystem of an application to another.

DTO的最常在N层应用所使用的服务层本身和UI层之间传送数据。这里的主要好处是,它减少了需要可以在分布式应用程序通过线路发送的数据量。他们在MVC模式也使伟大的车型。

DTOs are most commonly used by the Services layer in an N-Tier application to transfer data between itself and the UI layer. The main benefit here is that it reduces the amount of data that needs to be sent across the wire in distributed applications. They also make great models in the MVC pattern.

有关DTO的另一个用途可以是封装方法调用的参数。如果一个方法需要超过4个或5个参数,这非常有用。

Another use for DTOs can be to encapsulate parameters for method calls. This can be useful if a method takes more than 4 or 5 parameters.

在使用DTO模式,你也将利用DTO装配的。该装配用于从域对象创建的DTO,反之亦然。

When using the DTO pattern, you would also make use of DTO assemblers. The assemblers are used to create DTOs from Domain Objects, and vice versa.

从域对象DTO,然后再返回转换可以是一个昂贵的过程。如果你没有创建一个分布式应用程序,你可能不会看到从模式的极大的好处,因为 Martin Fowler的解释此处

The conversion from Domain Object to DTO and back again can be a costly process. If you're not creating a distributed application, you probably won't see any great benefits from the pattern, as Martin Fowler explains here

这篇关于什么是数据传输对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆