POCO VS DTO

编程入门 行业动态 更新时间:2024-10-25 12:17:30
本文介绍了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:看看这个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(领域驱动设计)定义的anti-corruption层(另一个链接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

本文发布于:2023-07-27 11:50:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222299.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:POCO   DTO

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!