Value Object
Last updated
Was this helpful?
Last updated
Was this helpful?
Value objects represent immutable and atomic data. They are distinguishable only by the state of their properties and do not have an identity or any identity tracking mechanism. Two value objects with the exact same properties can be considered equal. You can read more about value objects in article.
To define a value object with Cronus, create a class that inherits the base helper class ValueObject<T>
. Keep all related to the value object business rules and data within the class.
The base class ValueObject<T>
implements the IEqualityComparer<T>
and IEquatable<T>
interfaces. When comparing two value objects of the same type the properties from the first are being compared with the properties of the second using reflection. The base class also overrides the ==
and !=
operators.
Keep a parameterless constructor and specify a data contract for serialization.