Form validation and business validation are too large?

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?

: , . . , , .

+3
6

, , . , , , , , . , . , , "AddressLine1" "AddressLine2" .. , .

- , , , - , .

+1
  • ( )
  • -

, , , , . .

+6

, DRY, - ; . , , - , div html, ajax.

, , , , - , , - e-commerce .

, , hibernate ( java), -, , API . .

+3

- , , . - - ; . . , , Zend/Cake/Ci .. , ; V C, : http://en.wikipedia.org/wiki/Naked_objects

+1

, , , - " " - , -, , " t . , ( , - ), -.
, , (, Name FirstName LastName) - (, a State , Country be USA) .

0
source

Approval in both cases, the IS is redundant, but it is necessary. You want to check on the client that your user has the best user experience. It also reduces the load on your server. You should also check on the server side, since nothing falling on the wire should trust your application.

0
source

Source: https://habr.com/ru/post/1726442/


All Articles