DDD and validation of aggregate root
        Posted  
        
            by 
                Mik378
            
        on Programmers
        
        See other posts from Programmers
        
            or by Mik378
        
        
        
        Published on 2012-03-20T06:45:25Z
        Indexed on 
            2012/03/20
            11:38 UTC
        
        
        Read the original article
        Hit count: 357
        
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) ?
© Programmers or respective owner