Value Objects
A Value Object represents a conceptually whole value with no identity. It is defined solely by its attributes or properties and is considered immutable, meaning its state cannot be changed after creation. Two Value Objects with the same attributes are considered equal, regardless of their individual identities.
Characteristics of Value Objects:
Immutability: Once created, the state of a Value Object cannot be modified. Any changes to its properties result in a new Value Object instance.
Equality based on attributes: Value Objects are compared based on the equality of their attributes rather than their identities.
Side-effect-free: Value Objects should not have any behavior or actions associated with them. They are primarily used to hold and model data.
Lightweight: Since Value Objects are immutable and do not have identities, they are typically lightweight and easy to copy.
Replaceable: If two Value Objects have the same attributes, they can be replaced with each other without any impact on the domain logic.
Eiffel.Modelling.Abstractions NuGet package contains base ValueObject class. By using abstract ValueObject class you can define your value objects.
Example Location value object.
Last updated