Checking in the domain model?

I designed the domain model following DDD methodology. I would like to add confirmation.

Do you think adding domain model level validation is a good idea? If not, where should I check my domain objects?

thank

+3


source to share


3 answers


If validation rules are part of a business domain, they belong to the model.

The aggregate root is responsible for preserving the invariants it covers, so checking them falls under its responsibility.



If you find that the validation rules are very complex, you can create a validation service that will be used by the aggregate root for this function.

+8


source


It depends on what kind of check you have.

If only the client name and maximum length for the field is required, then it is not the responsibility of the domain itself. This should be an input confirmation.



If you are creating an online store and the order is invalid when not all of the items are in stock, then you have a real domain check.

Domain Driven Design 101 has some good examples starting on slide 44.

+2


source


See also: http://lostechies.com/jimmybogard/2009/02/15/validation-in-a-ddd-world .

"Instead of answering the question," This object is valid, "try answering the question," Can this operation be performed? ".

+1


source







All Articles