validation

Guarding Your Value Objects

When you apply the principle of Domain Driven Design (DDD) to your code, you start to notice all the small “rules” of the domain. Rules like “A name must not consist of whitespace, must have its whitespace trimmed on both ends and cannot be empty." Or “A donation amount must be greater than zero." Or “A book must have at least one page." It’s important that you can’t create value objects that violate those rules.