Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

Validation and formatting in a layered application

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pablolch@gmail.com - 17 Mar 2006 12:42 GMT
Does all the validation code resides on the business layer?
Where should reside the formating code (how to show dates, numbers,
phone numbers, etc)?
I underestand that the validating rules should reside at the business
layer. But if the business layer expects information (from the
presentation layer) the information itself must be in some format. For
example if business layer expects a number as a Double the presentation
layer should send a Double, not a string. To send a Double the
presentation layer should parse a string tiped by the user and it may
contain errors. ¿Do this validation should reside on the presentation
layer?

1) Which one (presentation or business) says that "3;14" is not a
Double but "3.14" is
2) Which one says that 3.14 must be displayed as "0003.14"?
Kevin Spencer - 17 Mar 2006 13:14 GMT
"3.14" is not a double. It's a string. The business layer defines the type
that is represented by the string, which the Presentation layer hands to it.
The Presentation layer must hand a double back to the business layer.
Therefore, the Presentation layer must convert the string to a double. If it
cannot, an exception will be thrown at the Presentation layer.

IOW, the Presentation layer must do validation. The business layer must
enforce business rules. So, depending upon your definition of "validation,"
the answer is "both."

Signature

HTH,

Kevin Spencer
Microsoft MVP
.Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.

Does all the validation code resides on the business layer?
Where should reside the formating code (how to show dates, numbers,
phone numbers, etc)?
I underestand that the validating rules should reside at the business
layer. But if the business layer expects information (from the
presentation layer) the information itself must be in some format. For
example if business layer expects a number as a Double the presentation
layer should send a Double, not a string. To send a Double the
presentation layer should parse a string tiped by the user and it may
contain errors. ¿Do this validation should reside on the presentation
layer?

1) Which one (presentation or business) says that "3;14" is not a
Double but "3.14" is
2) Which one says that 3.14 must be displayed as "0003.14"?
William Stacey [MVP] - 17 Mar 2006 17:27 GMT
One could think of your business layer as the api to the backend. The UI
and/or UIs consumers of that api. So the business layer needs to do
validation as the entry point for backend.  The UI does validation for the
user locally which can save round trips to the business layer for things you
know will not pass anyway and put up you UI dialogs, etc. It also creates
seperation as you can munge the data anyway you like in the presentation
layer, you just need to convert into something the BL api ultimately will
allow.

Signature

William Stacey [MVP]

Does all the validation code resides on the business layer?
Where should reside the formating code (how to show dates, numbers,
phone numbers, etc)?
I underestand that the validating rules should reside at the business
layer. But if the business layer expects information (from the
presentation layer) the information itself must be in some format. For
example if business layer expects a number as a Double the presentation
layer should send a Double, not a string. To send a Double the
presentation layer should parse a string tiped by the user and it may
contain errors. ¿Do this validation should reside on the presentation
layer?

1) Which one (presentation or business) says that "3;14" is not a
Double but "3.14" is
2) Which one says that 3.14 must be displayed as "0003.14"?
Michael Nemtsev - 17 Mar 2006 23:21 GMT
Hello pablolch@gmail.com,

Validation needs to be performed in both layers, but what and how is totally
depends on type of info.

Generally all BAL's incoming data need to be validated to be well-formed
in type(how it will be performed is up to you, but generally in message approach
systems XML Schemas serves the best of all). You need to be sure in app that
BAL will get valid data, it's crucial and very important first step.
Additional steps, for data consistensy may be performed either on BAL or
Application layer, but it may depends on your environment.
You can pre-test user input type in application (because it's very easy and
u need to calls to server) and re-test finally on BAL.

Returning to you sample. let's take "3;14" - it's a string not a number,
and it breaks type of data, this need to be validated in UI (i not saying
that u can't do it in BAL but UI is prefered for this)
Now about "0003.14", we already have a valid type - number, no compulsory
for UI to check it. But BAL might reject in due to some constrighs (and maybe
not :) ), for example value should be more then 1. I suggest you not to check
it in UI, only in BAL

> Does all the validation code resides on the business layer?
> Where should reside the formating code (how to show dates, numbers,
[quoted text clipped - 11 lines]
> Double but "3.14" is
> 2) Which one says that 3.14 must be displayed as "0003.14"?
---
WBR,
Michael  Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.