I have a question about form validation and business validation. I see many frameworks that use some kind of form validation library. You submit some values, and the library checks the values from the form. If you are not sure, this will show some errors on your screen. If everything goes according to plan, the values will be set to the domain objects. Here the values will or should rather be checked (again). Most likely, the same check in the check library. I know 2 PHP frameworks that have such a Zend / Kohana construct.
When I look at programming and some principles, such as Do not Repeat Yourself (DRY) and the principle of single responsibility (SRP), this is not very good. As you can see, it checks twice. Why not create domain objects that do the actual validation.
Example: A form with a username and email form. The values for the username field and the email field will be populated in two different domain objects: username and email address
class Username {}
class Email {}
These objects check their data, and if they are invalid, they throw an exception. Do you agree? What do you think of this question? Is there a better way to implement validation? I am confused by the fact that many frameworks / developers do this. Are they all wrong, or am I missing a point?
:
, . . , , .