【发布时间】:2011-02-22 23:47:02
【问题描述】:
嗨,我正在自学 oop 原则。我想知道这是否是 parametric polymorphism 的 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>
【问题讨论】:
-
这个代码是在 Daily WTF 上找到的吗?
标签: oop polymorphism dynamic-languages