POCO遵循OOP的规则.它应该(但不一定)有状态and行为.POCO源于马丁·福勒(Martin Fowler)[anecdote here]创造的POJO.他使用术语POJO使拒绝使用框架密集的EJB实现变得更加性感.POCO应在中的相同上下文中使用.网不要让框架支配对象的设计.
DTO的唯一目的是转移状态,不应该有任何行为.有关此模式的用法示例,请参阅Martin Fowler的explanation of a DTO.
区别在于:POCO describes an approach to programming(优秀的老式面向对象编程),其中DTO is a pattern用于使用对象"传输数据".
虽然你可以像对待DTO一样对待POCO,但如果你这样做的话,你就有创建anemic domain model的风险.此外,在结构上存在不匹配,因为DTO应该被设计为传输数据,而不是代表业务领域的真实结构.这样做的结果是,DTO往往比实际域更平坦.
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.
为什么 GetShortestDayName 返回的名称比预期的短?
使用 SSH.NET 查找具有特定文件名的最新 SFTP 文件
使用 Task.WhenAll 但需要跟踪每个单独的 Task 的成功
如何为多种文件类型设置 FileSystemWatcher 过滤器?
无法加载文件或程序集 Microsoft.Extensions.DependencyInjection.Abstractions,版本 = 1.1.0.0
System.ValueTuple 和 System.Tuple 有什么区别?
EnsureSuccessStatusCode 的使用和它抛出的 HttpRequestException 的处理
CryptographicException 未处理:系统找不到指定的文件