Sean Corfield wrote:
>On Tuesday, Mar 25, 2003, at 10:38 US/Pacific, Brad Howerter wrote:
>> <!--- work around the problem of there not being a way to access
>> 'super'
>> --->
>> <cfset user_new = new> <!--- sets user_new() as an alias for new() --->
>
>This creates a non-public instance member called user_new and assigns
>it a reference to the function user::new (to mix notations!)...
>
>> ************* EMPLOYEE CFC ********************************
>> <!--- Call the parent new() function. (works around the lack of
>> 'super') --->
>> <cfset this.user_new(argumentCollection=arguments)>
>
>...with the code as you have written it, this shouldn't work. You set
>the alias (user_new) in the non-public scope but you're trying to call
>it here via the public scope.
The code definitely does work as written; if it shouldn't then we've found a CFMX bug.
> I think user.cfc should have:
>
> <cfset this.user_new = new>
>
Okay, I'll use 'this' as you suggest. That does make sense. It does still work using
'this'.
>BTW, I think "new" is a terrible name for what is really an init()
>function. "new" is a reserved word in Java so this is confusing:
>
> <cfset x = createObject("component","thing")>
> <cfset x.new( args )>
>
>Whereas you would say this for creating a Java object:
>
> <cfset x = createObject("java","thing")>
> <cfset x.init( args )>
>
>I strongly recommend keeping to the same naming convention and using
>"init" for your constructor for consistency.
>
Okay, thanks for the tip.
>> <!--- now finish setting the properties --->
>> <cfset private.memberNumber = arguments.memberNumber>
>> <cfset private.department = arguments.department>
>
>This also shows that 'private' is a misnomer - if these were private,
>you could not access them in a derived component. I like the idiom,
>just not the name. I'd be inclined to use:
>
> <cfset instance = structNew()>
>
>"instance" is a nice, neutral name that doesn't imply anything other
>than 'instance data'.
Sounds good to me. I'll use instance instead.
>
>Sean A Corfield -- http://www.corfield.org/blog/
Here's the new version (I apologize for the lack of indentation, my tabs don't come
through to the mailing list properly):
************************* EMPLOYEE **************************
<cfcomponent name="Employee" hint="Employee info. If the User CFC has other arguments
than the ones listed here, you can go ahead and supply them to this CFC"
extends="User" access="public">
<cffunction name="init" hint="populates the Employee object. " output=1
returntype="void">
<cfargument name="name" type="string" hint="first and last name">
<cfargument name="USID" type="numeric" hint="WISE's usr_usid">
<cfargument name="mailAddress" type="string">
<cfargument name="phoneExtension" type="string">
<cfargument name="memberNumber" type="numeric" default=0>
<cfargument name="department" type="string" default=''>
<!--- Call the parent init() function. (works around the lack of 'super') --->
<cfset this.user_init(argumentCollection=arguments)>
<!--- now finish setting the properties --->
<cfset instance.memberNumber = arguments.memberNumber>
<cfset instance.department = arguments.department>
</cffunction>
<!--- set employee.new as an alias for new. Only neccessary if employee is also a
parent. --->
<cfset this.employee_init = init>
</cfcomponent>
******************** USER ***********************
<cfcomponent name="User" hint="WISE and WSES user info" access="public">
<cfset instance = structNew()>
<cffunction name="init" hint="populates the user object" output=0 returntype="void">
<cfargument name="name" type="string" hint="first and last name" default=''>
<cfargument name="USID" type="numeric" hint="WISE's usr_usid" default=0>
<cfargument name="mailAddress" type="string" default=''>
<cfargument name="phoneExtension" type="string" default=''>
<cfset instance.name = arguments.name>
<cfset instance.usid = arguments.usid>
<cfset instance.mailAddress = arguments.mailAddress>
<cfset instance.phoneExtension = arguments.phoneExtension>
</cffunction>
<!--- work around the problem of there not being a way to access 'super' --->
<cfset this.user_init = init> <!--- sets user_new() as an alias for new() --->
<cffunction name="getProperties" hint="Returns a copy of the properties" output="no"
returntype="struct">
<cfreturn duplicate(instance)>
</cffunction>
</cfcomponent>
-- Brad Howerter
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Your ad could be here. Monies from ads go to support these lists and provide more
resources for the community. http://www.fusionauthority.com/ads.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4