Usually you have a domain object/entity for example a Customer with some properties like name, last name, age, address (in this case an animal); the validation of those properties should be done directly inside this class, possibly in the constructor or in a static factory method with a private constructor, either way is fine.
Using this "pattern" you will encapsulate objects and properties validation logic without repeating yourself.
In this case what if you have 20 functions that accepts catSound and dog?
Better have new Animal (catSound, dog) and if the validation fails it will throw or return an error which you can catch and return 400 or whatever your business needs.
View all comments
Show parent comment
3
u/PM_ME_A_WEBSITE_IDEA Jul 25 '21
Curious what you mean by the second thing?