holisticon/ranked

Differentiate between type validation and domain validation

Opened this issue · 0 comments

Validation of data is an important step towards prevention of errors and it should be executed as early as possible in the system. We use JSR330 Bean Validation to prevent wrong data from being entered into the system and put most of the data inside of the model classes, event classes and command classes.

Aparently, we have to be careful with validation constraints defined on the domain types, and separate them from rules defined through the domain aggregate logic.

Type constraints should be independent of the domain state and configuration - example, the score (=number of goals shot in the match) is a positive number or zero.

Domain constraints have a semantical meaning and may depend on domain configuration - example, the score to win a match at holisticon soccer is 6. It is wrong to put the validation of the score == 6 into domain type, because it is defined inside of our bounded context == aggregate, and is not defined in the domain.

P.S. if someone wants to define it inside the domain, it should be not ScoreToMinMatchSet, but something like HolisticonScoreToWinMatchSet - which makes a naming different and would be probably a bad domain type.