Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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) ?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
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 '12 at 9:24
    
Yep, either that, or a static validator method. –  Martijn Verburg Mar 20 '12 at 9:28
    
Great :) Thanks –  Mik378 Mar 20 '12 at 11:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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