1

I am trying to understand the exact meaning of POCO actually (Yes i have read wikipedia already but still cannot get the main point :( ).

I understand that Value Object is an object that basically has only properties to keep the data without any behavior.

In this case it seems to me that POCO and 'Value Objects' has the same structure but the difference comes from the fact that POCO targets .net framework.

Am I correct?

Thanks.

pencilCake
  • 51,323
  • 85
  • 226
  • 363

1 Answers1

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:

Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154
  • +1, good explanation. The term *value object* is also used for objects which do not have their own identity and which are compared and passed by value. In C# these are the value types. In NHibernate these are the components. – Stefan Steinegger Apr 06 '11 at 09:08
  • +1 too. I'd add that it's often good practice to make valid objects immutable - i.e. their value can only be set on construction. – UpTheCreek Apr 06 '11 at 09:17