2

Suppose an aggregate root : MailConfiguration (wrapping an AddressPart object). The AddressPart object is a simple immutable value object with some fields like senderAdress, recipentAddress (to make example simple).

As being an invariant object, AddressPart should logically wrap its own Validator (by the way of external a kind of AddressValidator for respecting Single Responsibility Principle)

I read some articles that claimed an aggregateRoot must validate its 'children'. However, if we follow this principle, one could create an AddressPart with an uncohesive/invalid state.

What are your opinion? Should I move the collaborator AddressValidator(used in constructor so in order to validate immediately the cohesion of an AddressPart) from AddressPart and assign it to aggregateRoot (MailConfiguration) ?

1 Answer 1

2

Will AddressPart ever be used elsewhere outside of your MailConfiguration aggregate? If it is (or is likely to be) then the validation should absolutely stay with it.

Actually, I'd argue that the validation should stay wit it regardless. Even if the parent was 'responsible', it should simply delegate that call down to the children it has.

2
  • So if I follow your method, AddressPart should have a kind of IValidator passed in constructor for respecting SOP since it is immutable ? Do you agree ?
    – Mik378
    Mar 20, 2012 at 9:24
  • Yep, either that, or a static validator method. Mar 20, 2012 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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