What is the difference between Invariants and Validation Rules?

♀尐吖头ヾ 提交于 2019-12-02 23:43:04

Absolutely, validation is the process of approving a given object state, while invariant enforcement happens before that state has even been reached.

A corollary is that invariant enforcement is best performed by the thing that is being mutated (or created) itself, like a self-protection reflex, whereas validation is usually done by a third party.

The Always valid school of thought advocates the use of invariants over validation. I think it goes perfectly with DDD and Aggregates.

Yes, I think so

In DDD, validation rules can be thought as invariants. The main responsibility of an aggregate is to enforce invariants across state changes for all the entities within that aggregate.

You can refer more info in this page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!