On 1/17/06, Phillip Senn <[EMAIL PROTECTED]> wrote:
> myForm.cfm contains:
> <cfset myObj = CreateObject("Component","Components.myComponent")>
> <cfset Temp = myObj.Init(Application.DSN)>

I'll address this in more detail below, but is there a reason your
init() method doesn't just return the object itself?  That would allow
you to do this:
myObject = CreateObject("component",
"components.myComponent").init(Application.DSN);

Also you don't have to do <cfset Temp = ... > to call a method on a
CFC.  You can just do <cfset myObject.init()>

> MyComponent.cfc contains:
> <cfcomponent output="False">

I always use displayname in here as well so I can get the benefit of
the auto-documentation.

> <cffunction name="Init" output="False" returntype="void">

As I said above, I'd have init() return the object itself, so you can
use returntype="components.myComponent" or returntype="any" depending
on how rigid you want to be with your typing. ;-)  I tend to be pretty
rigid with typing unless I know I'm going to need the flexibility of
returning "any".

> <cfargument name="DSN" required="yes">

I always put a type in here as well:
<cfargument name="DSN" type="string" required="true" />

> <cfset Variables.DSN = arguments.DSN>

This works and keeps things out of the dreaded "this" scope.  (Do I
need to duck as I type that? ;-))

> </cffunction>
>
>
>
> <cffunction name="myFunction" output="False" returntype="query">
>
>                 <cfargument name="ID" type="numeric">

I assume this is required?  If so, I'd flag it as such.

>                 <cfset var result = "">

Exactly right--gotta var scope everything!

>                 <cfquery name="result" datasource="#Variables.DSN#">

Here you could go variables.dsn, or you could have a getter/setter for
your DSN as well.  This should work OK though.

>
>                 SELECT * FROM myTable WHERE myTableID =
> #arguments.myTableID#
>
>                 </cfquery>
>
>                 <cfreturn result>
>
> </cffunction>
>
>
>
> </cfcomponent>

The rest looks ok to me!
--
Matt Woodward
[EMAIL PROTECTED]
http://www.mattwoodward.com


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

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


Reply via email to