Answer the question
In order to leave comments, you need to log in
How to distinguish polymorphism in programming languages?
I watched Yandex's presentation on C++. There, polymorphism lies in the fact that we make a pointer to the parent class, by the way, why are we doing this?
And here it is purely based on virtual methods, but the exact same example can be reproduced in JS, PHP, Python? To immediately understand what polymorphism is.
I read in theory that polymorphism is the ability to choose the right method based on the type of data. But in other programming languages, there are no data types, as such, that is, we do not specify the data type, it is dynamically assigned by the interpreter, since polymorphism is defined in these languages?
Judging by the slides, polymorphism in C ++ does not come down to the use of the virtual keyword, which means that in other languages, everything can be presented differently.
In one video I found that polymorphism is when we can do this in a language:
Answer the question
In order to leave comments, you need to log in
You need a good book. This is one of the basic concepts and it is unlikely that you will study this issue on the Toaster.
Let's start with the fact that the main idea of polymorphism is to work with many types in the same way.
There are many types of polymorphism, starting with the simplest - parametric polymorphism, aka function overloading. In Python, for example, you can write print x and get that x on the screen. Moreover, we get a different result depending on the specific type x. In C++, you can write cout << x, you can write abs(x), and different actions will be performed depending on x. In C, for example, you would have to choose which function to call: abd, fabs, labs... because there is no function overloading in C.
Dynamic polymorphism works in a similar way: imagine an algorithm that should calculate the total amount owed. A person may have loans of various types, which are considered differently. Instead of writing an explicit algorithm of actions for each type of loan, the algorithm works with an abstract type of loans, for which the function Loan.CalculateDebtOnDate(Date) is defined. A specific calculation algorithm is hardwired into a specific Loan descendant type, the algorithm only asks what debt will be on a specific date, and it does not care what kind of loan it actually is.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question