小编Eul*_*ler的帖子

通过ColdFusion中的组件继承进行公私功能访问

我遇到了ColdFusion标记语言意外的问题。假设我具有以下组件。如果在“基本”组件中定义了公共功能和私有功能,那么当从扩展的“子”类型的实例中调用前者时,前者是否仍可以调用私有功能?

程序.cfc

<cfcomponent>

    <cffunction access="public" name="doOperation"> 
        <cfset this.checkValue(-14)>
    </cffunction> 


    <cffunction access="private" name="checkValue">
        <cfargument name="notNeg" required="yes" type="numeric">

        <cfif arguments.notNeg LT 0 >
            <cfthrow message="Negative Numbers not allowed"> 
        </cfif>
    </cffunction> 

 </cfcomponent>
Run Code Online (Sandbox Code Playgroud)

子程序

<cfcomponent extends="Program">

</cfcomponent>
Run Code Online (Sandbox Code Playgroud)

运行.cfm

 <cfobject component="SubProgram" name="this.instance">

 <cfset this.instance.doOperation()>                      <<<<----ERROR---->>>>
Run Code Online (Sandbox Code Playgroud)

ColdFusion引发错误

checkValue在component中找不到方法SubProgram。确保定义了方法...

这是什么问题?没有用于封装的核仁巧克力饼点!

coldfusion inheritance encapsulation function cfml

4
推荐指数
1
解决办法
1213
查看次数

标签 统计

cfml ×1

coldfusion ×1

encapsulation ×1

function ×1

inheritance ×1