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!
|