I don't know if this is a great idea but here is a suggestion

first I would do validation in the bean.  That is where I typically
make sure my data is well formed anyway.

Secondly I would have a parent bean that all of my beans extended. 
The parent bean would have any methods that are globally shared for
validation and are needed all over the place.

then as you need special case validation methods you can put them in
the subclass beans as you need them.


Now of course there are some draw backs to this; particularly if you
have alot of subclass beans

1. if you have 30 different validation functions and 20 are global but
5 work in 1/3 of the subclass beans, 2 work in 75%, 6 work in 18%, 10
work in 33%

at that point the super is only serving limited value and you might
end up with a bunch of  middle ground objects between the super and
your beans - not really a good situation

Now you could have all of the validation routines in the super.  Some
people will probably agree that doing that isn't so great since you
have a bunch of code being inheirited that is only partially needed in
the majority of the objects.  However, if you number of validation
routines is fairly minimal then I personally think that is a tradeoff
you could live with.


Bill




On Fri, 28 Jan 2005 09:25:16 -0600, Dawson, Michael <[EMAIL PROTECTED]> wrote:
> This was previously discussed in the "Validation" thread back in
> November, but I never really "got it".  This list has several new
> members so I would be interested in hearing new solutions, not that I
> discount the "elder's" opinions.  ;-)
> 
> I have a web-based form and I need to persist the data in a database.  I
> also want to validate the data and, if there are errors, reload the form
> and display the errors to the user.  (The form is self-posting to make
> it easier to re-populate the fields with just-submitted data.)
> 
> I also have a simple bean that contains only getters and setters that
> equate to the form fields.  The setters are all "typed" (e.g. String,
> Numberic, etc.) according to the requirements.  (This is the data that
> needs to be validated, eventually, before saving to a database.)
> 
> I have a DAO that Creates, Updates and Deletes a single record in the
> database.  (This DAO does not validate any data.  It only assumes the
> data passedto it has already been validated.)
> 
> This is my current situation as mentioned above:
> TheForm -> Bean -> DAO -> Database
> 
> If I need to validate the data from the form, where would the logic
> reside?
> 
> Should I use:
> TheForm -> TheFormValidationObj -> Bean -> DAO -> Database
> 
> Or, do I put the validation in one of the existing layers?  Keep in mind
> that I will probably need to reuse some of the validation functions for
> other objects.
> 
> If anyone could post a fully-working sample of this simple application,
> I'm sure many others would greatly appreciate it.
> 
> I have a simple working application, but, being new to any OOP thinking,
> some things just don't "feel right" to me.
> 
> Thanks
> M!ke
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email
> to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
> in the message of the email.
> 
> CFCDev is run by CFCZone (www.cfczone.org) and supported
> by Mindtool, Corporation (www.mindtool.com).
> 
> An archive of the CFCDev list is available at 
> www.mail-archive.com/[email protected]
> 


-- 
[EMAIL PROTECTED]
http://blog.rawlinson.us

I have 9 gmail invites,want one?
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]

Reply via email to