0

I m trying to understand the core concepts of DDD and I m having some troubles dealing with validations.

In fact, I m actually wondering where and when should I use specification pattern instead of Entity / ValueObject validations.

Moreover, I m trying to find a way to avoid this kind of validation in my Application service :

if(Email.isValid(emailString)){
  User usr = new User(emailString);
}

In fact, what could happen if I have multiple validation like 10 - 20 on certain field ? I don't neither want to throw multiple exceptions, which are, in my sense, dedicated to critical errors.

Any ideas ?

1
// Throws Hey,That'sNotEmailException
Email email = new Email(emailString);
User user = new User(email);

Alternative spelling

// Throws Hey,That'sNotEmailException
Email email = Email.from(emailString);
User user = new User(email);

Using explicit value types is great for supporting validation.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.