Michael,
Put them in the business layer and make them callable by the presentation
layer. My business layer returns record(s) and provides validation
mechanisms for individual fields and record-level validation, as well as
checking all the fields at once if desired.
This is always a thornier problem with web apps because the client-side
validation must be in a different language (JavaScript) and often has to
duplicate server-side validation logic, which ends up acting as a "safety
net". There really is no clean way around that other than to use server
controls for everything and rely on the server for all validation. This
makes development easier, but doesn't give the user the kind of "rich
experience" (immediate and specific feedback) they expect. And/or it
generates a lot of post back activity that burdens the server and slows down
the user.
Going in the other direction there's the matter of database rules /
constraints and where they should live. I think that most people seem to be
relying on the database itself to act as a "safety net" if nothing else --
at least for database-specific issues such as enforcing relationships
between tables.
In other words: in a web app, your presentation layer should validate
everything and should never let anything incorrect through to the business
layer, but the business layer is there as a safety net and a way to
formalize your business rules and share them across applications. Likewise,
your business layer should call the approparite things in the data layer
which should never issue any requests to the DB that would violate DB
integrity. But, the DB constraints are there as a safety net.
All of this effort makes more sense when you have many applications doing
overlapping tasks or sharing the same data. At the individual application
level, especially for a first project, sometimes it seems like a lot of
extra implimentation.
--Bob
"Michael Rodriguez" <mi**@nospamforme.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
If you're using a standard 3-tiered architecture, i.e. Data Layer->
Business Layer->Presentation Layer, where is the recommended place to put
data validations? Specifically, data validations such as "Please enter a
name."
It seems like the best place to put them, from the programmer's point of
view, is in the business layer. That way the same validations work for
either Winforms or Webforms. Also, if I redo my interface later, I don't
have to redo the work.
However, the best place to put them as far as my users are concerned is
probably the presentation layer. That way I can not only say "Please
enter a name", but I can set the focus to the name control and possibly
even turn on an error provider (which seem hokey at best).
Thoughts?
Mike Rodriguez