One option would be to use a "mode" setting in your object.  If it's
set to "full" then you do complete validation.  If it's set to
"nameEmail" then you only validate part of it.  Another option would
be to have a NamedUser with just the name fields, and then a FullUser
(or whatever) that extends NamedUser and adds more fields.  I can't
say whether or not that's a good idea; it depends on whether your
existing object model is appropriate for that type of inheritance
relationship.

However, before you go down that road, I'd take a second look and make
sure you're not trying to bastardize your user object simply to save
yourself some typing.  If your single user entity can legitimately
have different situations where different things are required, then
fine.  But if you're really using the same object to represent two
distinct entities that just happen to both be termed "user", then
you're going to run into trouble down the road trying to combine them.

cheers,
barneyb

On Tue, 4 Jan 2005 15:30:04 -0600, Dawson, Michael <[EMAIL PROTECTED]> wrote:
> Barney said, "I much prefer a validate() method separate from the
> individual getters and setters."
> 
> Sean pretty much said the same thing.
> 
> I can understand the reasoning behind these comments and I like the fact
> that I can wrap up temporary storage of data PLUS validation of that
> same data, all in one object.  That makes it very handy to carry around
> for multiple purposes.
> 
> On the other hand, that is where the limitation is, in my mind.
> 
> Let's say I have a user-related object with the following instance
> variables:
> 
> UserBean.cfc
> ID#
> SSN
> BirthDate
> FirstName
> LastName
> Email
> 
> I also have the setters and getters for each instance variable.  These
> are all string data types.
> 
> In addition, I have a validate() method that checks, obviously, for
> valid data.
> 
> I want to reuse this same user-related CFC for multiple purposes.  One
> use is with a DAO to manage the database operations.  This requires me
> to fill "all" variables and validate them.
> 
> My other use is to wrap up "some" instance variables, but not all, for a
> completely different use, but still user related.  For example, I only
> need to pass FirstName, LastName and Email.  Rather than create a new
> bean with only these instance variables, I just want to use "part" of my
> UserBean CFC.
> 
> This is all fine until I run the validate() method.  Then, it will tell
> me that ID, SSN and BirthDate are required and/or not of the necessary
> data type.
> 
> This leads me back to Roland's comment where he uses a struct as a data
> object and not an entire CFC.  In Roland's case, his struct can't
> validate itself as a CFC can.  Therefore, he must do validation outside
> of the data struct.
> 
> On the other hand, a struct can't define itself using an init() like a
> CFC can. (Unless you write a function that returns a struct with empty
> keys.)
> 
> To sum it up, how can I use a bean-type CFC to pass several data
> elements, validate the data, yet still not "always" require validation?
> 
> Thanks
> MAD
> 

-- 
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/

Got Gmail? I have 9 invites.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble 
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:189309
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to