嗨,我正在自学 oop 原则。我想知道这是否是 Cardellis 定义参数多态性的正确示例。请赐教。
该示例采用 cfml 的基于脚本的语法。
<cfscript>
Parent = createobject("component","webapp.model.Parent").init();
Child = createobject("component","webapp.model.Child").init();
GrandChild = createobject("component","webapp.model.GrandChild").init();
Test = createobject("component","webapp.model.DealWithObject");
dump(Test.getNumberOfParents(Parent));
dump(Test.getNumberOfParents(Child));
dump(Test.getNumberOfParents(GrandChild));
</cfscript>
<cfcomponent>
<cfscript>
// should deal with an infinte number of abstract data types (because of common structure)
public numeric function getNumberOfParents(component arg){
return -1 + arraylen(structfindkey(getmetadata(arguments.arg),"extends","all"));
}
</cfscript>
</cfcomponent>