Value Object - 3axap-4/Patterns GitHub Wiki

Value Object

A small simple object, like money or a date range, whose equality isn't based on identity.

The key difference between reference and value objects lies in how they deal with equality. A reference object uses identity as the basis for equalitymaybe the identity within the programming system, such as the built-in identity of OO programming languages, or maybe some kind of ID number, such as the primary key in a relational database. A Value Object bases its notion of equality on field values within the class. Thus, two date objects may be the same if their day, month, and year values are the same.
This difference manifests itself in how you deal with them. Since Value Objects are small and easily created, they're often passed around by value instead of by reference. You don't really care about how many March 18, 2001, objects there are in your system. Nor do you care if two objects share the same physical date object or whether they have different yet equal copies.

.NET has a first-class treatment of Value Object. In C# an object is marked as a Value Object by declaring it as a struct instead as a class. The environment then treats it with value semantics.

⚠️ **GitHub.com Fallback** ⚠️