A number of tutorials on polymorphism state that "Any object that can pass more than one IS-A test is considered to be polymorphic." I wonder what they mean by that, and if that's even a true statement.
From my understanding, (subtype) polymorphism is when you have the interface of the base class and the implementation of the derived class. Which would look like this:
Shape myShape = new Circle();
But the implication of every object that passes more than one IS-A test being polymorphic is that every object of every class in Java or C# is polymorphic all the time. ([With the exception of objects of type Object.] Since every class inherits from Object.) In other words this would be an example of polymorphism:
Shape myShape = new Shape();
This doesn't make sense to me since we know for a fact that inheritance and polymorphism are two separate concepts. But this implies that they are effectively the same thing, because as soon as a class inherits from another class, it becomes polymorphic.
I've tried to figure out some possible explanations as to why they said that. These are my guesses:
- Maybe being "polymorphic" and using polymorphism are two different things. It could be that saying that a class is polymorphic doesn't necessarily mean that the class is using polymorphism at that exact moment but rather that it has the potential of using polymorphism.
- Given the fact that polymorphism is possible due to the CLR using a virtual function table, maybe the CLR uses the vtable in a similar way during inheritance as it does during polymorphism, and that is why they said that a class that passes multiple IS-A tests is polymorphic. (idk, this is just a guess.)
- According to Bob Martin, phrases like "IS-A" and "HAS-A" are remnants of artificial intelligence programming and don't accurately reflect the relationships between classes in OOP. However, if a class is more than one thing, then it would take "many forms" in a vague interpretation of the word "polymorphism." We know that "polymorphism" is such a vague word that it can even include ad-hoc polymorphism (method overloading), even though it's not really polymorphism.
I don't know. These are just guesses as to why they said that a class that can pass more than one IS-A test is polymorphic. And to clarify, the article is speaking about subtype polymorphism in Java. Although, I think it works the same way as in C#.