Is this an example for parametric polymorphism?
Posted
by mrt181
on Stack Overflow
See other posts from Stack Overflow
or by mrt181
Published on 2010-05-23T18:41:14Z
Indexed on
2010/05/23
18:51 UTC
Read the original article
Hit count: 319
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>
© Stack Overflow or respective owner