I ask myself this same question every day.  How much work should the
setter do?  Should it know everything it needs to know to prevent an
error or invalid data from occuring?

Along these lines, which would be a better solution:
1. Have the setter throw an error on invalid data assignment.
2. Have the setter set any value that passes the argument test, then,
call a "validate" method to determine if the data is valid for its use
in the object.

M!ke

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Nando
Sent: Monday, November 01, 2004 6:07 PM
To: [EMAIL PROTECTED]
Subject: [CFCDev] Validation

Opinions? Is it best practice to include validation in a BO setter. I'm
just starting to add this kind of stuff to my objects and i'm wondering
how others handle it, and why.

<cffunction name="setIntScope" access="public" returntype="VOID"
output="false">
        <cfargument name="intScope" type="numeric" required="true" />
        <cfset arguments.intScope = fix(arguments.intScope) />
        <cfif (arguments.intScope LT 0) OR (arguments.intScope GT 2)>
                <cfset throwException("WebStudio Validation Error", "A
scope value of #arguments.intScope# is not valid.", "Valid values are 0:
Site, 1: Section, and 2: Page<br>Scope refers to the scope of the
content query executed for this content container.")>
        </cfif>
        <cfset variables.instance.intScope = arguments.intScope />
</cffunction>



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