Value Objects

A Value Object is an object you use to represent a value (duh). Value Objects are

  • immutable — you set the value in the constructor and never change it again
  • interchangeable — one $5 dollar note is equal to the next one

Any mutation on a Value Object should return a new Value Object. Otherwise, you’re likely to run into a problem known as aliasing. Imagine changing the amount on one Dollar object and having another Dollar object also change.