Polymorphism is a key object-oriented programming concept but it can be hard to understand initially. The primary purpose of using polymorphism is to make applications more maintainable. When we speak of polymorphism, we typically say that a method exhibits polymorphic behavior.
Note
A method is said to be polymorphic if the behavior of the method is dependent on the object it is executing against.
Suppose we want to draw something. Each class may have a method called draw
that it can use to draw itself. For example, a circle class might have a draw method that actually draws itself as a circle. A person class might have a draw method that displays an image of that person. The signature of the methods is identical.
Thus, if we apply the draw
method against different objects of different classes with the same ultimate base class, then the result of the draw will differ depending on whether we are applying the draw
method against a circle or a person. That is polymorphic behavior...