POCO VS DTO [英] POCO vs DTO

查看:192
本文介绍了POCO VS DTO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

POCO =平原老CLR(或更好:类)对象

POCO = Plain Old CLR (or better: Class) Object

DTO =数据传输对象

DTO = Data Transfer Object

在此帖子是有区别的,但坦率地说大多数时候我读到描述POCO的DTO的定义方式的博客:DTO的是用于应用层之间移动数据的简单数据容器

In this post there is a difference, but frankly most of the blogs I read describe POCO in the way DTO is defined: DTOs are simple data containers used for moving data between the layers of an application.

是POCO和DTO同样的事情?

Are POCO and DTO the same thing?

(PS:看看这个<一href="http://$c$cidol.com/csharp/applying-domain-driven-design-and-patterns/$p$pparing-for-Infrastructure/POCO-as-a-Lifestyle/">great关于POCO文章作为一种生活方式)

(ps: look at this great article about POCO as a lifestyle)

推荐答案

一个POCO遵循面向对象的规则。它应该(但并不一定)有状态的的行为。 POCO来自POJO,由马丁·福勒[此处 轶事]杜撰。他使​​用的术语POJO,以此来使其更性感拒绝框架沉重的EJB实现。 POCO应该在.NET中的同一范围内使用。不要让框架决定你的对象的设计。

A POCO follows the rules of OOP. It should (but doesn't have to) have state and behavior. POCO comes from POJO, coined by Martin Fowler [anecdote here]. He used the term POJO as a way to make it more sexy to reject the framework heavy EJB implementations. POCO should be used in the same context in .Net. Don't let frameworks dictate your object's design.

一个DTO的唯一目的是转移状态,应该没有问题。看到一个DTO 的Martin Fowler的解释使用这种模式的一个例子。

A DTO's only purpose is to transfer state, and should have no behavior. See Martin Fowler's explanation of a DTO for an example of the use of this pattern.

下面的区别: POCO描述了一种编程(良好的老式面向对象编程),其中 DTO是一种模式用于使用数据传输对象。

Here's the difference: POCO describes an approach to programming (good old fashioned object oriented programming), where DTO is a pattern that is used to "transfer data" using objects.

虽然你可以把波苏斯喜欢的DTO,你运行创造一个贫血的域模型如果你这样做的风险所以。此外,有一个在结构不匹配,因为DTO的设计应来传输数据,而不是重新present业务域的真实结构。这样做的结果是,DTO的往往比你的实际域更加平坦。

While you can treat POCOs like DTOs, you run the risk of creating an anemic domain model if you do so. Additionally, there's a mismatch in structure, since DTOs should be designed to transfer data, not to represent the true structure of the business domain. The result of this is that DTOs tend to be more flat than your actual domain.

在任何合理的复杂领域,你几乎总是最好创建单独的域波苏斯,并将其转换为DTO的。 DDD(领域驱动设计)定义的<一个href="http://books.google.com/books?id=7dlaMs0SECsC&lpg=PA366&ots=ulHUZZRdr2&dq=anti%20corruption%20layer&pg=PA364#v=onepage&q&f=false">anti-corruption层(另一个链接<一个href="http://moffdub.word$p$pss.com/2008/09/21/anatomy-of-an-anti-corruption-layer-part-1/">here,但要做到最好的事情是买的书),这是一个很好的结构,使分离清晰。

In a domain of any reasonable complexity, you're almost always better off creating separate domain POCOs and translating them to DTOs. DDD (domain driven design) defines the anti-corruption layer (another link here, but best thing to do is buy the book), which is a good structure that makes the segregation clear.

这篇关于POCO VS DTO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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