views:

81

answers:

3

hi,

i have a design problem.. it may seem that i'm giving you too much details, but those are important.

say i have a very large input form, with a complicated input, that requires quiet complicated validations, includes validations of relations between different inputs. being probably a very burdensome form for the user, i'd like to give him the ultimate experience, and i really don't want to be restricted by programing difficulties here. i thought that idealic every control should have an empty value at start except those of course, that have default values (the problem is DateTimePicker and such are not supporting empty value).

now the user can fill in any of the controls, in any order he would like. once he has leave the control, the program will validate the control's value, and any of the others validations which are concern with that control, and with other controls that are all non-empty (have been filed in already).

if there are any validation errors, the control is painted in some color, and in some side panel it will specify the errors (in a user friendly language of course, rather than exceptions' descriptions).

if there are errors that concerns to more than one control, only the last one that has been changed is painted.

i'd really like to keep to as many OOP concepts here..

so i have my logic classes, that are dealing with calculating the output and stuff like that. obviously those have nothing to do with the gui. now all of these complicated validations should be also in the logic classes' properties etc. but should be used in the gui as well, so i think there should be something like static validate methods (within the logic classes), that will be used in the gui, and in the logic classes them self.

the problem is, a logic class might contain up to 20 maybe 30 fields to validate... will that static method take 30 parameters? is that okay or is there more acceptable solution?

i'm a bit lost for anything beyond that.. but i'm quite sure there already are some conventions for these situations... i know it has something to do with design patterns, but i have no idea what design patterns there are, which are dealing with such cases, and where should i read about them.

my question basically is how do i integrate the validation of the logic classes and the gui, in the neatest way.

if i already in that, i don't want to open a new question for these:

as i mentioned, i need a method here, that get all the input, all the fields of the class, and somehow perform all the validation checks on the non-null values (if there is a validation check that concern to a few parameters, and even one of them is null, the validation shall not be execute). if you have any interesting ideas, i'd like to hear.

another problem i bump into, is the non-emptyale controls, such as DateTimePicker.... it's really ugly that it will have a certain value, while it should not... don't you think?

p.s.

sorry about my english.. i was too tired to write it perfectly..

EDIT1 working with windows

+2  A: 

will that static method take 30 parameters?

Yes but what if you pass your object into your static validation method instead of all its properties individually ex.

public static class YourClassRules
{
    public List<SomeSortOfValidationItem> Validate(YourClass obj)
    {
        var results = new List<SomeSortOfValidationItem>()

        if (obj.YourProperty.Length >= 200)
        {
           results.Add(new SormSortOfValidationItem("YourProperty", "Length must be less than...");
        }
        //etc.
    }

}

my question basically is how do i integrate the validation of the logic classes and the gui, in the neatest way.

There are several different frameworks available. It would be helpful to know if your doing windows or web. Then we could make some recomendations.

another problem i bump into, is the non-emptyale controls, such as DateTimePicker.

Are you having issues with the controls or the properties that are bound to the controls. I often use DateTime? or Nullable which will allow for a null value.

Hope this helps.

J.13.L
weird.. i've commented here already, but it disappeared... anyway: 1) not a good solution because obviously the class does not allow instances with illegal values. 2) working with windows 3) i'm having problems with the control it self.
Itay
A: 

DataAnnotations can be very easy to implement and very effective. Read this answer for an alternative that can extend further. Also, this question has some great gems regarding validation models too.

cottsak
A: 

Spring has a very good DataBinding and validation API. Since there is a Spring.NET version, I'd recommend looking into it.

duffymo