附录一
ChangeState(State toState, DomainObject object)
我有业务规则,检查目的地国是否有效,或是否属于目前“状态”的范畴,我如何在技术上检查这些规则,而没有首先确定目标领域的国家? 它对新国家的首个感到错,如果一个或多个规则中断,国家。
One solution I came up with is to create some context object that drives the validation eg. ChangeStateContext that contains the DomainObject along with the State that is to be set.
Another related question is how to report back from the ChageState call how it went?
I can collect all validation rules that broke and throw an exception with those rules that the caller can catch and handle accordingly or I can add a return type on the ChangeState-method like ValidationSummary that contains information about broken rules and such. What is best practices in these cases?