Is this an example for parametric polymorphism?
- by mrt181
Hi i am educating myself oop principles. I would like to know if this is a correct example of Cardellis definition of parametric polymorphism. Please enlighten me. The example is in cfml's script based syntax.
<cfcomponent>
<cfscript>
public numeric function getlength(any arg, string type){
switch (arguments.type){
case "array":
return arraylen(arguments.arg);
break;
case "struct":
return structcount(arguments.arg);
break;
case "string":
return len(arguments.arg);
break;
case "numeric":
return len(arguments.arg);
break;
case "object":
// gets the number of parent classes, substracting the railo base class
return -1 + arraylen(structfindkey(getmetadata(arguments.arg),"extends","all"));
break;
default:
// throw was added to railo as a user defined function to use it in cfscript
throw("InvalidTypeArgument","The provided type argument is invalid for method getlength");
}
}
</cfscript>
</cfcomponent>