Patrick,

Thanks for inspiring me to build a test case. Here it is. It roughly
approximates the situation. Strangely enough, my test case returns a value
of "true" even if the getter in the child is private. In the app, changing
the getter in the child to private alters the funtionality of the "verify"
method. It only works correctly if the getter is public.

<sigh>

In any case, i agree with Ken's reasoning and i'm going to pass this value
into the function rather than accessing it directly.

<cfcomponent displayname="parent">

        <cffunction name="verify" access="public" returntype="boolean" 
output="no">
                <cfset var someID = getMyID() />
                <cfif IsNumeric(someID)>
                        <cfreturn true>
                <cfelse>
                        <cfreturn false>
                </cfif>
                <cfreturn>
        </cffunction>

</cfcomponent>

<cfcomponent displayname="child" extends="parent">

        <cffunction name="init" access="public" returntype="child">
                <cfargument name="myID" type="string" required="true" />
                <cfset setMyID(arguments.myID) />
                <cfreturn this />
        </cffunction>

        <cffunction name="getMyID" access="private" returntype="string"
output="false">
                <cfreturn variables.myID />
        </cffunction>

        <cffunction name="setMyID" access="private" returntype="VOID"
output="false">
                <cfargument name="myID" type="string" required="true" />
                <cfset variables.myID = arguments.myID />
        </cffunction>

</cfcomponent>

<!--- test.cfm --->
<cfset myChild = createObject('component','Child')>
<cfset myChild.init(7)>
<cfset valid = myChild.verify()>
<cfoutput>#valid#</cfoutput>

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of Patrick McElhaney
Sent: Thursday, November 11, 2004 8:15 PM
To: [EMAIL PROTECTED]
Subject: Re: [CFCDev] Sanity check


<!--- super.cfc --->
<cfcomponent name="Super">
  <cffunction name="functionA()" returntype="string">
                <cfreturn functionB()>
        </cffunction>
</cfcomponent>

<!--- sub.cfc --->
<cfcomponent name="Sub" extends="Super">
        <cffunction name="functionB()" returntype="string" access="public">
                <cfreturn "Hello, World">
        </cffunction>
</cfcomponent>

<!--- test1.cfm --->
<cfset super = createObject("Component", "Super")>
<cfoutput>#super.functionA()#</cfoutput>

<!--- test2.cfm --->
<cfset super = createObject("Component", "Super")>
<cfoutput>#super.functionB()#</cfoutput>

Neither of these tests should work. They didn't work for me.

A supertype should not need to call a function in a subtype. If that's
really the case you should "pull up" the function from the subtype to
the supertype.

This will work:

<!--- super.cfc --->
<cfcomponent name="Super">
  <cffunction name="functionA()" returntype="string">
     <cfreturn functionB()>
  </cffunction>
  <cffunction name="functionB()" returntype="string" access="public">
     <cfreturn "Hello, World">
  </cffunction>
</cfcomponent>

<!--- sub.cfc --->
<cfcomponent name="Sub" extends="Super">
  <cffunction name="functionC()" returntype="string" access="public">
    <!--- since I extend Super I inherit functionB() and can use it --->
    <cfreturn functionB()>
  </cffunction>

</cfcomponent>

HTH,

Patrick

--
Patrick McElhaney
704.560.9117
http://pmcelhaney.blogspot.com
I still have 5 gmail invites.
----------------------------------------------------------
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
[EMAIL PROTECTED]



----------------------------------------------------------
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 
[EMAIL PROTECTED]

Reply via email to