Concepts of polymorphism and object-oriented programming
Polymorphism in object-oriented programming, refers to the ability to access a diverse range of roles through the same interface. That is, the same identifier can take different forms (different function bodies, different behaviors) depending on the context in which they are present. The polymorphism can be established by overload, over-writing and dynamic linking.
This term refers to using the same identifier or operator in different contexts and with different meanings.
If each necessary functionality needed to write a method, the resulting code would be unmanageable. Suppose that Java developers have created a method to echo a string, a different one to write a whole one for a double, and so for all possible combinations, would be almost impossible to know all these methods. Instead, with “System.out.println ()” or “System.out.println ()” can write any message on the screen.
This type of coding we are permitted due to overload, which applies to constructors and methods.
Method overloading makes the same name represent different methods with different types and number of parameters, managed within the same class. In the context of OOP, method overloading refers to the possibility of having two or more methods with the same name but different functionality. That is, two or more methods with the same name that perform different actions the compiler will use one or the other depending on the parameters used. This also applies to developers (in fact, is the most common application of the overload).
We can differentiate several overloaded methods through its parameters, either by the amount, type or order of the same.
Overwriting
Applies to the overwriting methods and is directly related to the inheritance refers to the redefinition of the base class methods in the subclasses. For example, the inheritance relationship in the example of the figures though the base class “Figure” has the methods “calcularArea” and “calcularPerimetro” subclasses “Circle”, “Square”, “Triangle” and “Rectangle” redefine these methods since the calculation of area and perimeter of each is different.
Dynamic Link
This allows objects to invoke operations on ignoring the current rate until they run the code. That is, we can define elements such as type and instantiating a type inherited. But what use is clearly the type of an object and then make this decision?.
With that definition in java object types can be produced by linking back (late binding), we should be worried about what kind of element will pass a message, because the compiler will decide on which method to execute what purpose according to how you create the instance.
This concept is quite complex to understand, because we are used to defining the elements according to what we need. That is, I need you declare an integer as an integer, to declare an item as a type and then use it as another? The answer is not always possible to determine exactly what type of item to be used when implementing our program.
You must have at least one inheritance relationship to determine a base type for the declaration, whatever the subtype. Here is an example that clarifies things a bit: We see that the method “Move” calls the move of a mammal, and he knows not what kind of mammal he is, it works and calls the corresponding method to that specific object called ( ie first a cat and then a dog). Without the dynamic linking, we would have to create a method “Move” to the mammals of type “Cat” and another for type “Dog”.
Consider another example of Bespoke Software Development where the instances are created at random: We see that the method generalInstruments creates random instances of different types of instruments and arrangement of elements of the instruments is filled with different elements of which we know are only based objects” Instrument “. However, the methods “tocarInstrumento” and “afinarInstrumento” parameter is received as an instrument property like “tune” or “touch”.