1

我实际上正在尝试理解 POCO 的确切含义(是的,我已经阅读了维基百科,但仍然无法理解要点:()。

我知道值对象是一个基本上只有属性来保存数据而没有任何行为的对象。

在这种情况下,在我看来,POCO 和“值对象”具有相同的结构,但不同之处在于 POCO 以 .net 框架为目标。

我对么?

谢谢。

4

1 回答 1

7

Plain Old CLR Objects

The term POCO (Plain Old CLR Object) is commonly used to refer to a .NET class that doesn't have any direct or indirect dependencies on external third party libraries. The word POCO itself doesn't say anything about whether the object contains only data or both data and behavior. However it does indicate that the class is built on top of the .NET platform.

Value Objects

A Value Object (or Data Transfer Object) is a general design pattern describing the use of objects as data structures to transport data between different parts of a system. These objects typically contain only data and no behavior other than accessor methods.

Given the above definitions it is fair to say that a Value Object built on the .NET platform without dependencies on third party frameworks is a POCO. By the same token a POCO may or may not be a Value Object depending on its structure and how it's used.

Related resources:

于 2011-04-06T08:43:18.737 回答