473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Architecture question

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
Nov 17 '05 #1
6 1351
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

Nov 17 '05 #2
"Bob Grommes" <bo*@bobgrommes.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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.


Hi Bob,

How exactly are you doing this? Do you just set the row.RowError to the
first error you find then display that in the winform? Do you also set the
focus to the field in question? If so, how do you pass that info back to
the presentation layer? Some code samples would be great... <g>

BTW, my particular case is mostly a windows app, although some webform
options are possible down the road.

Thanks,

Mike Rodriguez
Nov 17 '05 #3
Mike,

In a WinForms app you generally call the business layer validator for a
field from that control's Validating event, to determine whether or not the
value is correct, e.g. something along this line:

string strMessage;
if
(myBusinessObjectForTheAppropriateTable.FieldIsVal id("FieldName",this.Text,ref
strMessage)) {
errProvider.SetError("");
// or do the above in the Validated event, which won't fire if
// we set the CancelEventArgs below.
} else {
errProvider.SetError(this,strMessage);
eventArgs.Cancel = true;
}

That would keep the focus on the errant control and put up an error
notification next to it.

The control knows what field it corresponds to in the DB. Or sometimes I
have what I call a BusinessView that orchestrates several tables and has the
attributes of interest from all of them.

There are really about 100 right ways to do this, and 1000 wrong ones. If
you're new to it, you might want to spend some time studying up on
multi-tier designs and possibly adopt one of many that are out there at low
or minimal cost as a starting point. For example, Rockford Lhokta (sp?) has
a pretty good framework out there that comes out of his book, and there are
various code generation products that can spit out your data and business
layer code for you.

One thing you will want if you do n-tier design, is a code generator.
Otherwise you will quickly drive yourself crazy writing alot of boring
gruntwork code.

--Bob

"Michael Rodriguez" <mi**@nospamforme.com> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
"Bob Grommes" <bo*@bobgrommes.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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.


Hi Bob,

How exactly are you doing this? Do you just set the row.RowError to the
first error you find then display that in the winform? Do you also set
the focus to the field in question? If so, how do you pass that info back
to the presentation layer? Some code samples would be great... <g>

BTW, my particular case is mostly a windows app, although some webform
options are possible down the road.

Thanks,

Mike Rodriguez

Nov 17 '05 #4
IMO you have to put them in each layer:

- In the presentation layer, to be able to get the label text of the
textbox, so you can compose an error message consistent with the user
interface, and also you can put the focus on the control.

- In the business layer, because your component can be called from who
knows...

- In the database, using a NOT NULL constraint, to avoid invalid data no
matter who tries to insert it.

--
Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"Michael Rodriguez" <mi**@nospamforme.com> escribió en el mensaje
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

Nov 17 '05 #5
Bob,

I've been doing UIs for about 15 years, I'm just new to C# and the n-tier
design aspect of it. I did get a code generator, My Generation, that was a
*major* time saver. I generates my data layer, web service layer, and
business layer for me, all based on the tables in the db. I don't know what
I would do without it!

I have a couple of issues with the validating event approach. First of all,
what if they don't leave that field? They might just close the screen,
which would call my form level save changes event, but not the field level
event. Also, I'd rather not have to attach event handlers to every field.

Your initial response did give me an idea I hadn't thought of. I think I'll
have the business layer do the validations, as you said. But instead of
throwing exceptions, it will assign column error descriptions to the fields
in error. Then then the windows form can cycle through the columns of the
table and attach error providers to the appropriate controls. That way the
business layer does the logic and the winform layer does the presenting of
the errors. The best of both worlds...

Thanks,

Mike
"Bob Grommes" <bo*@bobgrommes.com> wrote in message
news:ut**************@TK2MSFTNGP09.phx.gbl...
Mike,

In a WinForms app you generally call the business layer validator for a
field from that control's Validating event, to determine whether or not
the value is correct, e.g. something along this line:

string strMessage;
if
(myBusinessObjectForTheAppropriateTable.FieldIsVal id("FieldName",this.Text,ref
strMessage)) {
errProvider.SetError("");
// or do the above in the Validated event, which won't fire if
// we set the CancelEventArgs below.
} else {
errProvider.SetError(this,strMessage);
eventArgs.Cancel = true;
}

That would keep the focus on the errant control and put up an error
notification next to it.

The control knows what field it corresponds to in the DB. Or sometimes I
have what I call a BusinessView that orchestrates several tables and has
the attributes of interest from all of them.

There are really about 100 right ways to do this, and 1000 wrong ones. If
you're new to it, you might want to spend some time studying up on
multi-tier designs and possibly adopt one of many that are out there at
low or minimal cost as a starting point. For example, Rockford Lhokta
(sp?) has a pretty good framework out there that comes out of his book,
and there are various code generation products that can spit out your data
and business layer code for you.

One thing you will want if you do n-tier design, is a code generator.
Otherwise you will quickly drive yourself crazy writing alot of boring
gruntwork code.

--Bob

"Michael Rodriguez" <mi**@nospamforme.com> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
"Bob Grommes" <bo*@bobgrommes.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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.


Hi Bob,

How exactly are you doing this? Do you just set the row.RowError to the
first error you find then display that in the winform? Do you also set
the focus to the field in question? If so, how do you pass that info
back to the presentation layer? Some code samples would be great...
<g>

BTW, my particular case is mostly a windows app, although some webform
options are possible down the road.

Thanks,

Mike Rodriguez


Nov 17 '05 #6
Michael,

I have ValidateAll() and ValidateRecord() methods in my business layer, in
addition to Validate().

Validate() -- for validating indvidual fields
ValidateRecord() -- for record-level validation, that is, integrity between
different fields
ValidateAll() -- calls Validate() for all the fields, then ValidateRecord().

So ... if some UI quirk causes a field validation to be skipped, it's still
caught when the record is saved, because at that point I call ValidateAll().

I actually have a class in the business object called MessageList (derives
from System.Collections.Specialized.StringList) which the UI can access.
This allows the UI to present a complete list of complaints to the user if
desired; or, you have the option to present the message for just the first
error encountered.

--Bob

"Michael Rodriguez" <mi**@nospamforme.com> wrote in message
news:uQ**************@TK2MSFTNGP14.phx.gbl...

I have a couple of issues with the validating event approach. First of
all, what if they don't leave that field? They might just close the
screen, which would call my form level save changes event, but not the
field level event. Also, I'd rather not have to attach event handlers to
every field.

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: comp.lang.php | last post by:
I can't possibly reproduce the code for this as the 2 classes in question are about 1500 lines each and condensing is in this case impossible due to algorithmic logic dependencies. Let's say you...
3
by: Michael Crawford | last post by:
Hi, Where would one start for this type of application: I want to create an vb.net container application that has the gives the end user the ability to install and uninstall plugins or add-in...
6
by: Tim | last post by:
Hello everyone. I visit this board pretty regularly but have never posted. My question is an application architecture question... so hopefully it's okay to post in the dotnet general forum. I...
2
by: hans | last post by:
Hi! I am new to .NET (coming from Java). We have to implement a desktop application which extracts data from a database, does some analysis, filtering etc. and displays the results. I have...
6
by: Gary James | last post by:
This may not be a direct C# question, but since I'll be using using C# for development, I thought I'd pose the question here. I'll soon be involved in the design of a new software product that...
1
by: dilip ranganathan | last post by:
Howdy All I have a quick question on an architecture I am trying to implement. I want to implement something similar to a pub-sub architecture. Is it possible to broadcast event notifications...
1
by: benmorganpowell | last post by:
I have a small windows service which connects to a POP3 server at defined intervals, scans the available messages, extracts the required information and inserts the data into a SQL database. I am...
3
by: Ken H | last post by:
Hi I have a question about architecting solutions.. I have a part of a project which requires me to track person details (name, addresses, etc... Should I be creating Person objects, Address...
2
by: John A | last post by:
I have a Web Service that I am reponsible for that we use for data integration purposes. Recently I have been tasked with sending some of this data to a third party. Because they need to receive...
13
by: rrs.matrix | last post by:
hi i have to detect the type of CPU. whether it is 32-bit or 64-bit.. how can this be done.. can anyone please help me.. thanks.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.