In inherited CFCs, if you have a function named the same as a parent
function (as is often the case), it overrides the parent CFCs definition.
This is proper, but sometimes you want to be able to call the parent
function as well, and there is no good way to do it.  You can't just call
super.new(), for example.  But here's a pretty fair work-around.   I have an
employee cfc that inherits a user cfc.  The user cfc has a new function to
set the user's properties.  The employee cfc has one extra property, the
member number.  When you have a new employee, employee's new() function is
called.  It needs to run the user new() function and then set the member
number.   super.new() doesn't work, but this will:

************* USER CFC
********************************************************************
<cfcomponent name="User" hint="WISE and WSES user info" access="public">
<cfset private = structNew()>

<cffunction name="new" 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 private.name = arguments.name>
        <cfset private.usid = arguments.usid>
        <cfset private.mailAddress = arguments.mailAddress>
        <cfset private.phoneExtension = arguments.phoneExtension>
</cffunction>

<!--- 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() --->

<cffunction name="getProperties" hint="Returns a copy of the properties"
output="no" returntype="struct">
        <cfreturn duplicate(private)>
</cffunction>
</cfcomponent>


************* EMPLOYEE CFC ********************************
<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="new" hint="populates the Employee object.  " output=0
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 new() function.  (works around the lack of
'super') --->   
        <cfset this.user_new(argumentCollection=arguments)>

        <!--- now finish setting the properties --->
        <cfset private.memberNumber = arguments.memberNumber>
        <cfset private.department = arguments.department>
</cffunction>

<!--- set employee.new as an alias for new.  Only neccessary if employee is
also a parent. --->
<cfset employee_new = new>
</cfcomponent>

****************************************************************
If the User CFC has more functions that need to be called from a child, just
set additional user values, i.e.:
<cfset user.getProperties = getProperties>


What do you think?  Note, I use 'user_new' for the alias as opposed to
'user.new', because 'user.new' doesn't work for some reason.  Also, I'm
using 'private' for properties instead of 'this', since 'private' is private
and 'this' is public.  But that doesn't matter with regard to the 'super'
work-around.

***
The information in this e-mail is confidential and intended solely for the
individual or entity to whom it is addressed. If you have received this
e-mail in error please notify the sender by return e-mail, delete this
e-mail, and refrain from any disclosure or action based on the information.
****

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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
Get the mailserver that powers this list at http://www.coolfusion.com

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to