Ensuring correctness

In the previous section we were checking the entity constructor parameter to be valid to ensure the newly created entity object is also correct. We applied a constraint, which does not allow creating a new entity without specifying the valid parameter value. By doing this, we are guarding our domain model against getting objects that aren't valid. It is one of the essential functions of the domain model as such, and since we are embracing behavior-first approach, this type of code needs to be a part of the domain model implementation and not "outsourced" to external layers, like UI or application service layer. Of course, since our domain model is the system core, it takes a few hops for data to move from the user interface to domain objects. It is a valid approach to do preliminary quality check on the data that tries to enter the domain model before it does. It improves the user experience due to much faster feedback. However, the ultimate control is always performed inside the domain model itself since it shall never come to an invalid state.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.57.164