Perhaps in the app I have a feature allowing users to send feedback using a form with some validation logic:
Where would you put these validation logic, either in domain layer
as business logic or in presentation layer
as UI logic?
These logic are applied for all applications (android, iOS, web). Please note that we already had server side validation.
I think many developers do that in Presentation
layer, specifically in ViewModel/Presenter/Controller
(not in Activity/Fragment/View!
). My approach is to put that logic in Domain
layer. Why?
ValidationException
with explanation. ValidationException
will contain list of invalid parameters, type of validation they failed (minLength, maxLength, emailPatternMismatch etc..), what is expected (20 char at max etc..). ViewModel/Presenter/Controller
gets this ValidationException
and here we have Presentation logic. Now it decides what to render, how to render. Do we render error of all invalid inputs or only first invalid input? What text/color should be shown (based on data in ValidationException) ? Do we render error as popup/textView/tooltip? After all presentation decisions are made and new model is created, View
just! renders using that model.fun validate():ValidationOutcome
function. I don't think it is problem to put validation logic of Business Model in itself. All UseCases would call model.validate()
only. There is dependency between Model and ValidationOutcome.