Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Need this question's answer as early as posible.

What I have tried:

I cannot find the exact solution. That's why I need a proper solution.
Posted
Updated 18-Aug-22 16:43pm
Comments
Rick York 18-Aug-22 15:12pm    
Do you really think someone is going to supply you with an answer? Search engines are much more efficient than forums for acquiring answers and usually you will learn more from them.
Member 15627495 21-Aug-22 11:17am    
hello,

with polymorphism, you can write a function with several 'input type' :

function display_var(int var)
function display_var(float var)
function display_var(char var)
function display_var(string var)

that is the aim of polymorphism.

That is far too broad a question for a Quick Answers forum. You need to get hold of a book* on Object Oriented Programming, in order to understand all the concepts.

*or use Google.
 
Share this answer
 
Comments
Member 15653662 18-Aug-22 13:07pm    
I need just an explanation.I didn't take it urgently.
Richard MacCutchan 19-Aug-22 3:21am    
Then do as I suggested and search for the details. There is neither the time nor the space in a Quick Answers forum to explain the philosophy behind OOP.
Quote:
I cannot find the exact solution. That's why I need a proper solution.

There is no "exact solution" to a generic question like this: it depends on so many different variables. You will have to study pretty much the whole of OOPs design and formulate your own opinion.

If your course notes do not cover it - and they probably do - then start here and read some articles, follow some links, see what you can find out: Why do we use polymorphism and templates - Google Search[^]
 
Share this answer
 
The point of polymorphism
Imagine you have a class that describes common attributes for graphical interface objects, and that's just that and is therefore defined as an abstract class (one that cannot generate direct instances).
Given that, you create specialized classes that derive from the abstract class that have members in common, this new class defines a button. And following this principle you specialize a class to draw panels and so on. But a common thing in GUI elements is the "contains" relationship, a panel can contain a button, a button a panel... And this is possible thanks to polymorphism, at runtime it becomes possible to arbitrarily assign objects derived from the abstract class with each other.
This was a quick attempt to bring up a use case of polymorphism.

And when it comes to object orientation, the importance is in the organization of data. For example you model a structure once, and when you need that structure again, there's no point in copying the previous lines, just generate an instance of that structure. Imagining a case, templates are useful so that the same structure can adapt to different types of data at compile time, for example, we have an array that precisely uses only integers but it would be nice if we could work with float without having to copy the implementation of that array and change the data type from int to float, right? These are templates in a basic way.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900