views:

33

answers:

1

In Adobe Flex, it is possible to declare a public function, which can be overridden in a class that extends that function's class:

public class class1 {
    public function method1 {
        public var var1:string = "hello world";
    }
}

public class class2 extends class1 {
    override public function method1 {
        alert.show(super.var1 + "!");
    }
}

See how that public var can be accessed by the extending class?

I am wondering if such a thing is possible in ColdFusion. I know that Component-specific variables are stored in the "this" and "Variables" scope, and the "var" scope is private to the method in which it is declared, but, is there something...in between?

p.s. sorry for the most vague tags ever on this....

+3  A: 

I see what you're trying to do, but the answer is no, it's just not possible to do that in ColdFusion. That's not how inheritance works in CF.

However, you do have access to run the parent class' version of the function; and you could use a component-global scope, like Variables (or the user's session scope, etc.)

<cfcomponent displayName="parent">
    <cffunction name="foo">
        <cfset variables.foo = 1 />
    </cffunction>
</cfcomponent>

<cfcomponent displayName="child" extends="parent">
    <cffunction name="foo">
        <cfset super.foo() />
        <cfdump var="#variables#" />
    </cffunction>
</cfcomponent>
Adam Tuttle
So, that dump of Variables with display the parent class' Variables scope??
Eric Belair
Yes and no. The super.foo() will run in the context of the child object, so when it sets variables.foo, it will be available in that context (that of the child object) later in the same request.
Adam Tuttle