Appropriate Location for Validation Logic WIth the new Split Domain Layer #450
-
I like splitting out Trigger Handler logic from the domain class. But I wanted to ask if there was a sense of where actual validation and default code logic should live. If my ContactTriggerHandler calls its onValidate() method, should that validation logic be a part of ContactTriggerHandler, or should it be making a call to the Contacts domain class?
Or should we prefer something like this?
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
I'd vote for the former. I strive to have all relevant logic in the domain class with the trigger handler being essentially a pass-through to the appropriate domain. |
Beta Was this translation helpful? Give feedback.
-
I concur with @stohn777 on this. |
Beta Was this translation helpful? Give feedback.
-
I would add that adding a method like |
Beta Was this translation helpful? Give feedback.
-
Thanks for the great conversation. Glad I am doing it right. |
Beta Was this translation helpful? Give feedback.
I would add that adding a method like
validate()
to the Domain class is the preferred pattern .. and the Trigger just calls<domain>.validate()
rather than having the Trigger need to know aboutcheckEmail
and any other future validations you might apply