ValueObjects Overview

What is a ValueObject ?

As explained previously, a ValueObject is a modddel that holds a "value", which can be made up by one or multiple member parameters.

The "value" is validated by one or multiple validations, grouped in one or multiple validation steps. Each validation either passes successfully, or fails with a ValueFailure (subclass of Failure).

ValueObjects Kinds

There are two kinds of ValueObjects : SingleValueObject and MultiValueObject. The difference between the two is that SingleValueObject enforces having only one member parameter.

Generally, you'll want your ValueObjects to contain one field only, so you'll mostly be using SingleValueObjects. For example, if you want to create a Person model that has a firstName, lastName and age, you'll usually want to create a separate SingleValueObject for each field, and then create a Person entity that groups the three ValueObjects.