What is a Value Object?
In Domain-Driven Design (DDD), a Value Object is an immutable type that is defined by its attributes rather than an identity. Unlike an Entity, which is uniquely identified by an ID, a Value Object is considered equal to another Value Object if all its properties are the same.
Key characteristics of a Value Object:
1. Immutability: Once created, a Value Object cannot be changed. If you need a different value, you create a new instance.
2. No Identity: Value Objects don’t have an identity; two Value Objects with the same data are considered equal.
3. Behavior over Data: Though they hold data, they also encapsulate behavior related to that data.
For example, a "Money" object with attributes like amount and currency can be a Value Object. Two instances of Money with the same amount and currency are considered equal, and it is immutable (no direct change after creation).
In summary, Value Objects help make your domain model more expressive and focused on behavior rather than technical implementation.