Click here to Skip to main content

Welcome to the Lounge

   

For lazing about and discussing anything in a software developer's life that takes your fancy except programming questions.

Technical discussions are encouraged, but click here to ask your programming question.

The Lounge is rated PG. If you're about to post something you wouldn't want your kid sister to read then don't post it. No flame wars, no abusive conduct, no programming questions and please don't post ads.


 
GeneralRe: How do you do it... PinmemberNagy Vilmos14-Dec-12 4:20 
GeneralRe: How do you do it... PinmvpOriginalGriff14-Dec-12 4:42 
GeneralRe: How do you do it... Pinmember d@nish 14-Dec-12 4:17 
GeneralRe: How do you do it... PinmemberDeathByChocolate14-Dec-12 4:18 
GeneralRe: How do you do it... Pinmember d@nish 14-Dec-12 4:23 
GeneralRe: How do you do it... PinmvpRichard MacCutchan14-Dec-12 4:41 
GeneralRe: How do you do it... PinmemberMarco Bertschi14-Dec-12 5:08 
GeneralRe: How do you do it... PinprotectorMarc Clifton14-Dec-12 4:52 
So, the first non-flippant response:
 
First, recognize that validating inputs is a "pattern" for which you might want a general purpose solution. Second, recognize that there are a variety of solutions that you may want to support, resulting in several kinds of implementations:
 
1) Use the input control to ensure that non-valid data is never entered - create specialized controls that let you do things like range checking, excluding invalid characters, validation by regex, etc.
 
2) Use metadata to specify in the code itself what the validation logic should be, either "constants" to specify things like ranges or "typeof" that instantiates a validator class containing a validation method.
 
3) If the class maps to a database, provide enough information to the underlying ORM to perform the validation when the record is created.
 
4) Use the database itself, either in the schema definition (which is limited) or with PL/SQL code and insert / update triggers.
 
5) Create a "class-schema", possibly in XML, which maps the fields of the class to methods or validation information.
 
6) Use self-validating types. Rather than "string", use a type that defines exactly what the behavior is that you want for that string. So, for example, you might have a type "Phone" that obviously is going to do very different validation than "surname."
 
Some of these approaches require reflection, some do not, and depending where the data needs to validated (on user input for example, or validating millions of records in a DB) the performance hit of reflection is acceptable, in other scenarios it is not, so you want something else.
 
My preference is to push the issue to the source - whatever is generating the data (user input, for example) should perform the validation there so that you can guarantee that the data being put into the object is already correct, and also to use more concrete types that define the validation, formatting, etc., rather than the more abstract and general-purpose types like "string" or "int".
 
Marc

AnswerRe: How do you do it... PinmemberRavi Bhavnani14-Dec-12 5:39 
GeneralA little weekend- optimization contest PinmemberVuNic14-Dec-12 3:47 
GeneralRe: A little weekend- optimization contest Pinmemberharold aptroot14-Dec-12 4:02 
GeneralRe: A little weekend- optimization contest Pinmember_Peeves14-Dec-12 4:05 
GeneralRe: A little weekend- optimization contest PinmemberChris Meech14-Dec-12 4:07 
GeneralRe: A little weekend- optimization contest PinmemberSimon_Whale14-Dec-12 4:08 
GeneralRe: A little weekend- optimization contest PinmemberChris Meech14-Dec-12 4:37 
GeneralRe: A little weekend- optimization contest PinmemberBig Daddy Farang14-Dec-12 7:12 
GeneralRe: A little weekend- optimization contest PinmemberChris Meech14-Dec-12 7:50 
GeneralRe: A little weekend- optimization contest PinmemberDeathByChocolate14-Dec-12 4:20 
JokeRe: A little weekend- optimization contest PinmemberVuNic14-Dec-12 4:30 
GeneralRe: A little weekend- optimization contest PinmvpOriginalGriff14-Dec-12 4:09 
GeneralRe: A little weekend- optimization contest PinmemberSimon_Whale14-Dec-12 4:12 
GeneralRe: A little weekend- optimization contest PinmemberDeathByChocolate14-Dec-12 4:16 
GeneralRe: A little weekend- optimization contest PinmvpOriginalGriff14-Dec-12 4:24 
GeneralRe: A little weekend- optimization contest PinmemberDeathByChocolate16-Dec-12 18:42 
JokeRe: A little weekend- optimization contest PinmemberVuNic14-Dec-12 4:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web03 | 2.8.150302.1 | Last Updated 5 Mar 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid