I have tried to understand exactly what Polymorphism in OOP means. All of the tutorials I have read say pretty much the same thing:
'Polymorphism is the fact that if class A
inherits/extends class B
, than an object of class A
could either be referred to as an object of class A
or an Object of class B
'.
Thus if in a game I have several type of missiles, and they all extend the Missile
class, I can create an array of Missile
s and they will all be able to be inside it, because they are all types of Missile
s, even though directly they are SpeedMissile
or ExlpodingMissile
or whatever.
Is this the definition of Polymorphism? Is that all? It is considered a primary principle in OOP, but somehow I can't figure out why it is so important. Also, essentially it's just a consequence of the inheritance principle. Then why is it so important?