asp.net - Do validators duplicate business logic? -


I know that the waiters of an application to check the data input in the presentation layer (such as regex, required fields etc) It is possible to use. ), And to show a message and / or required marker icon. Data validation is usually in the business layer

Edit: I know that presentation verification is good, and it notifies the user, and that it is not infallible fact Is it not that I see the same thing in two places effectively?

Yes and no.

It depends on the architecture of your application. We will assume that you are building an N-level application, because in most days these applications follow that model.

Validation in the user interface is designed to provide immediate feedback - with the other input to execute at any place in the first place, to prevent functionality in lower levels, the system user For example, you would not want to try to contact the user without the authentication of the user's name and password from the Active Directory server. Validation at this point saves you the time involved to include an object in an instant, setting it up and making an unnecessary round trip on the server, which you can easily tell through simple data inspection.

Class Library is another story here, you are validating business rules though it can be argued that verification in the user interface and validation in class libraries is similar, I would disagree Business rule verification becomes more complicated. In this case, your rule may be more subtle, and can detect things that can not be collected through the user interface. For example, you can apply a rule that states that the user can execute a method only if all class properties have been properly started, and only if the user is a member of a specific user group. Or, you can specify that an object can be modified only when it has not been modified in the last twenty four hours. Or, you can just specify that a string value can not be empty or empty.

In my mind, though, properly designed software, the library uses a common mechanism to implement both the UI and the dry from the classroom (if possible). In most cases, it is possible (in many cases, the code is very trivial, it is not worth it.)


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -