ColdFusion中的繼承
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”