I was watching a Google Tech Talks video, and they frequently referred to polymorphism.
What is polymorphism, what is it for, and how is it used?
I was watching a Google Tech Talks video, and they frequently referred to polymorphism.
What is polymorphism, what is it for, and how is it used?
In object-oriented programming, polymorphism refers to a programming language's ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes.
Polymorphism is the ability to use an object in a given class, where all components that make up the object are inherited by subclasses of the given class. This means that once this object is declared by a class, all subclasses below it (and thier subclasses, and so on until you reach the farthest/lowest subclass) inherit the object and it's components (makeup).
Do remember that each class must be saved in separate files.
The following code exemplifies Polymorphism:
The SuperClass:
The father, a subclass:
The child, another subclass:
The execution method, references Parent class to start:
Note that each class needs to be declared in separate *.java files. The code should compile. Also notice that you can continually use maidenName and familyTree farther down. That is the concept of polymorphism. The concept of inheritance is also explored here, where one class is can be used or is further defined by a subclass.
Hope this helps and makes it clear. I will post the results when I find a computer that I can use to verify the code. Thanks for the patience!
Polymorphism gives you the ability to create one module calling another, and yet have the compile time dependency point against the flow of control instead of with the flow of control.
By using polymorphism, a high level module does not depend on low-level module. Both depend on abstractions. This helps us to apply the dependency inversion principle(https://en.wikipedia.org/wiki/Dependency_inversion_principle).
This is where I found the above definition. Around 50 minutes into the video the instructor explains the above. https://www.youtube.com/watch?v=TMuno5RZNeE