"one thing I could see as a problem is that you have to pass in a 
list of field names to your init().  Which makes me nervous because if 
the application requirements change, you have to change the code where 
you pass in the list"

Sorry, I should probably have gone into more detail here, but I didnt want to 
confuse the issue.

In actual fact, the beans are embedded into a business object whose fields / 
properties are defined in a database or xml file. The beans fields are created 
dynamically when the business object factory creates and inits the business 
object.

So I just add / modify a property in the framework admin, and all the beans / 
forms / validators / SQL / documentation will pick that up across the entire 
app.

See, now Im going off topic! 

Anyway, glad to see that someone else uses a similar method, and im not just a 
crackpot.


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of Peter J. Farrell
Sent: 14 October 2005 09:30
To: [email protected]
Subject: Re: [CFCDev] Inside the CFC: use Getter/Setter or Instance
Scope


Kerry wrote:

>This isnt a perfect OO implementation because it is completely untyped, but
>I have essentially generic beans that only have 3 functions:
>
>init
>- accepts a list of field names, and uses them to create a struct in the
>variables scope
>
>setValues
>- accepts a struct or query, and looks for the fields defined in init,
>setting the appropriate struct keys where found
>
>getValues
>- returns a duplicate of the struct
>
>I have done this because a lot of my beans have 10+ fields, and frankly,
>calling 10 sets and 10 gets seems a hideous waste of resources to me, both
>my time and the processors.
>So, its not perfect, but it does make it impossible to set or access the
>values directly, and it gets the job done much quicker - (write once, use
>everywhere), which equals rent paid, gas in the tank, food on the table.
>
>Anyone care to comment on / rubbish this method?
>  
>
I'm going to repeat myself a bit here.  A little background first, so 
there isn't any confusion.

My init() the required cfarguments that my bean represents.  My argument 
names always match my form names (unless something funky is happening).  
In theory, I just push an argumentCollection and what matches gets set.  
I don't have to call 10+ setters as my init() does it for me as well as 
sets default data if an argument is missing.  I find that if I make the 
API of my bean more concrete, my applications are better documented and 
my control of the API is strict.  Again, this is very important when 
working in a team environment and you want your team to do things the 
same way every time.

Kerry, one thing I could see as a problem is that you have to pass in a 
list of field names to your init().  Which makes me nervous because if 
the application requirements change, you have to change the code where 
you pass in the list.  I think the bean should "know" something about 
itself without being feed the information that allows itself to know.  
Plus, if I want to know the field list - I can't just look at th bean, I 
have to hunt for it in some other code.  The less files I have open in 
my IDE the better - I hate having to open 10 files just to decipher what 
is going on.  Maybe I'm just a control freak, but being able to fire up 
the cfcexplorer on a bean and seeing all the accessors, arguments, etc. 
is very satisfying (as well as cheap/fast documentation - use hints) and 
makes for much easier application maintenance.

Since I maintain Rooibos Generator, I use that code generator a lot.  
;-)  I'll admit it's not perfect, but really a great way to create a 
boilerplate for your beans.  The question I ask is that if a code 
generator can do something for you in 30 secs, why not take that time 
and make your maintenance cycle come with less stresss?

Again, it's good to have documentation - why not let your code document 
some of itself (as long as you use hints to help)? 

Also, if you are working with multi-step forms and beans...I use this 
little ditty to help populate the bean in steps - it only sets data from 
the argumentCollection that has a matching field in the bean.  It does 
require an array of bean field names, but Rooibos generates that for me 
in the properties section so I don't have to worry about it:

    <cffunction name="setStepInstance" access="public" output="false" 
returntype="void"
        hint="Populates bean data. Useful to popluate the bean in 
steps.<br/>
        Throws: rethrows any caught exceptions">
        <cfset var i = "" />
        <cfset var data = arguments[1] />
        <cfset var temp = "" />

        <cftry>
            <cfloop from="1" to="#arrayLen(variables.beanFieldArr)#" 
index="i">
                <cfset temp = variables.beanFieldArr[i] />
                <cfif StructKeyExists(data, temp)>
                    <cfinvoke method="set#temp#">
                        <cfinvokeargument name="#temp#" 
value="#data[temp]#">
                    </cfinvoke>
                </cfif>
            </cfloop>
            <cfcatch type="any">
                <cfrethrow />
            </cfcatch>
        </cftry>
    </cffunction>

-- 
Peter J. Farrell :: Maestro Publishing
http://blog.maestropublishing.com

Rooibos Generator - Version 2.1
Create boilerplate beans and transfer objects for ColdFusion for free!
http://rooibos.maestropublishing.com/

Member Team Mach-II - It's coming...we're in a code freeze!



----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

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' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

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


Reply via email to