Mozier's weblog

<cfweblog author="Mozier" attention="ColdFusion,BlueDragon,CFML,Model-Glue,Mach-ii,etc" />
  订阅 订阅  :: 管理

ColdFusion中的继承

Posted on 2004-08-14 20:33  Mozier  阅读(562)  评论(0编辑  收藏  举报

ColdFusion中的继承体现在CFCs,用法就是在<cfcomponent>中加入属性extends,简单的说,sub.cfc通过继承parent.cfc,就自动拥有了parent.cfc中的(constructor构造器中的)变量、属性和公开的(public)方法,比如:

<!--- parent.cfc --->
<cfcomponent>
  <cffunction name="getSth">
    <cfreturn "this is parent class">
  </cffunction>
</cfcomponent>

<!--- sub.cfc --->
<cfcomponent extends="parent">
  <cffunction name="getSthFromParent">
    <cfreturn super.getSth()>
  </cffunction>
</cfcomponent>
<!--- test.cfm --->
<cfset Obj = createObject("component", "sub")>
<cfset temp = Obj.getSthFromParent()>
<cfoutput>#temp#</cfoutput>

test.cfm将输出:“this is  parent class”