Lost Password?


Go Back   CodeCall Programming Forum > Software Development > General Programming

General Programming Non language specific, Assembly, Linux/Unix, Mac and anything not covered in other topics. Talk about Programming Theory here.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-20-2008, 05:33 PM
serges123 serges123 is offline
Newbie
 
Join Date: Jun 2008
Posts: 1
Rep Power: 0
serges123 is on a distinguished road
Question Validating a collection in business layer: best practices

Good day,

First of all, sorry for my English, it is not my mother tongue.

Here is a simplified version of my problem.

I got a web form that construct a RegisterForm object. That RegisterForm object contains a collection of Options.

After that the form as been submitted, I construct a RegisterForm object that contains a collection of Options based on the form fields. Then, I pass that RegisterForm object to my business layer, to insert it into the database

Here is my question: The collection of Options objects in the RegisterForm has to be validated. For example, the user cannot select the Option A and B together, but can select Option A and C. What is the best practice for validating it? Is it by creating a AreOptionsValid() in the RegisterForm object? Is it by wrapping the collection of Options in a TheOptions class and call IsValid on it? Of course, the real system is more complex and I don't wanna validate the collection of Options in the web form, I have to validate it in the business layer.

And if the collection is not valid, what should I return to the web form... A custom exception? A OptionsError object?

So what are your thoughts about that? I am looking for the best practices here.

Thank you very much!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 06-22-2008, 12:15 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default Re: Validating a collection in business layer: best practices

I do not believe the Business Layer should be responsible for validation. In my framework, I have a class that us used strictly for common validation purposes (valid email address, web address, ect...). I would suggest you create a separate class for your validation thus creating a more decoupled code (you never know when it will be used again).

As for what to do when your collection is not valid, I would simply print out an error. I use exceptions when there could be errors PHP cannot recover from. This provides an elegant way to exit the application. A invalid object can easily be handled by you, without exiting the application.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Animated Ripple effect (Simple) - Flash MX 2004 ahsan16 Photoshop Tutorials 10 05-22-2008 06:54 AM


All times are GMT -5. The time now is 06:57 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads