如何有效地使用DTO对象(数据传输对象)? [英] How to effectively use DTO objects (Data Transfer Objects)?

查看:847
本文介绍了如何有效地使用DTO对象(数据传输对象)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是实现DTO的最佳方法是什么?

What is the best way to implement DTOs?

我的理解是,他们是在对象之间传输数据的方法之一。例如,在一个ASP.Net应用程序,你可以使用一个DTO从$ C $发送数据的C-背后的商业逻辑层组件。

My understanding is that they are one way to transfer data between objects. For example, in an ASP.Net app, you might use a DTO to send data from the code-behind to the business logic layer component.

什么其他的选择,比如刚刚发送数据作为方法参数? (这会是最简单的asces wher有较少的数据派?)

What about other options, like just sending the data as method parameters? (Would this be easiest in asces wher there is less data to send?)

有关静态类,只是保存数据,可以由其他对象(一种全球asembly数据存储类)的引用是什么? (这是否破坏封装太多了吗?)

What about a static class that just holds data, that can be referenced by other objects (a kind of global asembly data storage class)? (Does this break encapsulation too much?)

用于每个传送约一个通用的DTO是什么?这可能是使用了一点比较麻烦,而且减少了与工作需要的类(减少杂波对象)。

What about a single generic DTO used for every transfer? It may be a bit more trouble to use, but reduces the number of classes needed to work with (reduces object clutter).

感谢您分享您的想法。

推荐答案

感谢所有有益的想法......

Thanks for all the helpful ideas...

摘要+我拿到这个:

- 如果移动并没有太多的地方移动数据量小,常规参数可能就足够了。

--If there is a small amount of data to move and not too many places to move it, regular parameters may suffice

- 如果有大量的数据和/或许多对象要移动到,一个专门创建的对象可能是最简单的(DTO对象)

--If there is a lot of data and/or many objects to move it to, a specially created object may be easiest (DTO object).

- 可以通过各种对象引用(而不是通过)全球数据对象似乎就被皱起了眉头......不过,我不知道是否有有时没有特定子系统中为它的地方?它是减少数据传递的量的一种方式。它推良好的封装的限制,但具体层内的特定情况下,也许它可以添加到简单的班particluar assemply。因此,人们会失去类级封装,但仍然有集级封装。

--A global data object that can be referenced (rather than passed) by various objects would seem to be frowned on...however, I wonder if there isn't sometimes a place for it within a particular sub-system? It is one way to reduce the amount of data passing. It does push the limits of "good encapsulation", however in specific instances within specific layers, perhaps it could add simplicity to a particluar assemply of classes. Thus one would lose class-level encapsulation, but could still have assembly-level encapsulation.

这篇关于如何有效地使用DTO对象(数据传输对象)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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