Handling Properties Limits

G

Guest

I am developing the middle tier of an application. The middle tier will
return custom classes that represent the data in the database. So then let me
illustrate my problem:

Database has a table called Person. In the Person table is a job description
field called JobDescription and it is a Varchar (50). Therefore it is limited
to 50 characters by the database.

In my middle tier I have a class called Person and it has a property called
JobDescription and is coded as shown below:

public string JobDescription{get{return
mJobDescription;}set{mJobDescription= value;}}

The presentation layer (asp.net web application) never talks to the database
and totally rely's on the middle tier to handle data processing. The web
application should not assign a job description that is more than 50
characters.

This begs the question from me: What is the proper (OOP) way to handle this?
Should I test and throw an exception in the set clause if the value being
assigned exceeds 50 characters or allow the exception to get thrown by
ADO.Net in the middle tier? I feel that it would be faulty to rely on the web
application to test for it.

Any thoughts?
 
M

Mohammad

This is an area where things get a little bit muddy. Ideally, valiation
rules such as string size limits should be checked in one place, and
one place only. Again, ideally, this place should be the business logic
layer, or the middle tier as you have referred to it, since one should
strive for as much database independence as possible.

However, this is not very practical. The ASP.NET application should
implement simple validation logic, because this would reduce the number
of posbacks required in the case of invalid data.

Again, the middle tier should implement more advanced validation
because not doing so would cause unencessary roundtrips between the
database access layer and the business logic layer.

So, while not very OOP, the most practical implementation is to
implement validation rules on all layers, when possible.

I would highly recommend that you take a look at Rockford Lhotka's
CLSA.NET framework
(http://www.lhotka.net/ArticleIndex.aspx?area=CSLA .NET), and perhaps
get yourself a copy of his book, Expert C# Business Objects. His
framework covers this topic and many others, like O/R mapping, data
binding to Windows and Web cotnrols, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top