DDD Question: Where does required info validation belong for an Entity?
Let’s say I have a small hierarchy of object: Faults and Parts. A Fault can contain many parts, and a part has no meaning without being associated to a Fault. To ensure that I have no Parts without a parent Fault, I have this basic code in place:
This ensures that I never have a Part in an “invalid” state – without an owning parent.
I also have a business rule that say that I’m not allowed to have a Part without a description. My typical implementation of this business rule has been in the UI layer – my Presenter would have the logic to require a user to enter a description when creating adding a part to a fault.
Here’s the question:
Should this “require a description” logic be in the UI layer (Presenter) the way I have it, or should I put it in the Part object and have an IsValid flag of some sort on that object?
I don’t like having this coded in the presenter only. It makes the business rule very easy to break – create a part from anywhere else, and you can ignore this rule. But I’m not sure I like it in the Part object, because it would make the presenter difficult to code. How would I execute the specific view.ShowDescriptionRequiredMessage() method if the rule is coded in the Part?
Any opinions, suggestions, articles, etc. are very welcome. I’m very interested in hearing how other people are handling this situation.