A value object is immutable and has no external identity: its meaning, equality, and comparison come from its attributes. Changing a value creates another object or raises an error. section 4.5
Use the pattern when an object represents a value rather than a globally tracked entity:
- Prevent modification after construction. section 4.5
- Prevent dynamic extension, removal, or inheritance. section 4.5
- Define equality from relevant properties instead of an identifier. section 4.5
- Provide string and primitive representations when arithmetic or concatenation should feel natural. section 4.5
Money
Money('USD', 5) can produce new values with plus, minus, times, rounding, or negation. Thus Money('USD', 3).plus(Money('USD', 7)).equals(Money('USD', 10)) is true, while changing amount directly fails.


