On Dec 10, 2003, at 8:55 AM, Jon Gunnip wrote:
In order to populate an Article object one needs to pass in a struct that has all the required names for the component's instance variables.

An alternative approach is to use a bunch of <cfarguments>:
<cfargument name="Title" >
<cfargument name="Description" >

Now that <event-bean> is part of the framework, I'm going to deprecate FormObjectBeaner and recommend that bean components have an init() method using that alternative approach (so they can be initialized by <event-bean> without specifying the fields in the tag).


It seems to me like using a struct to initialize a component (and using an argumentCollection) seriously breaks enscapsulation because the user of the component must know the name of all your required instance vars.

Not really - this is used for form processing so the bean (component) is being initialized from the form fields passed in. The article.cfc is a little lazy in that respect - it probably should do this instead:


        <cfset variables.instance = structNew() />
        <cfset variables.instance.myVar1 = arguments.data.formField1 />
        <cfset variables.instance.myVar2 = arguments.data.formField2 />
        ...

The code in the example just happens to use the same names for the instance data as for the form fields.

Using <cfargument> seems to have better encapsulation, but it is more code to write.

Using <cfargument> to type validate form input data is not the way to go - you want to be able to accept the form input and then validate it but if you use <cfargument> the function won't accept the input data so you'll get a CF exception instead of a more controlled behavior.


Hope that helps clarify the intent.

Sean A Corfield -- http://www.corfield.org/blog/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

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