PDA

View Full Version : Polymorphism



zSilver_Fox
07-17-2005, 07:58 AM
Well, I'm new here... but no need for my intro.

Does anyone know any guides or examples that explain Polymorphism? All the examples I've found are usually lacking in descriptions and other stuff... not fun.

If you're wondering about my skill level, I know most of all the basics, enough to use pointers, and take advantage of inheritence.



Thanks in advance. I'm now off to the VPC section.

bobbobson
07-19-2005, 01:42 AM
You can learn all the aspecs of OOP from basicly anywhere. Pollymorphisum is the art of.... hmm/ how do i explain it. You have multiple functions with the same name and with differnt parameter. Then the compiler choses the approprate function based on the parameters you send. I hope im right, well i think i am ;). I hope that helps you.


- Michael.

eshbach
07-19-2005, 06:28 AM
You can learn all the aspecs of OOP from basicly anywhere. Pollymorphisum is the art of.... hmm/ how do i explain it. You have multiple functions with the same name and with differnt parameter. Then the compiler choses the approprate function based on the parameters you send. I hope im right, well i think i am ;). I hope that helps you.


- Michael.

It's a lot more than overloading a function.

Say you have an abstract class Fruit
Say you have a class Apple which extends Fruit
Say you have an array of Fruit FruitBasket[]

Now say Fruit has a Function called peelSkin() which returns the String "Skin removed from fruit, now ready for eating".

However, in the case of the apple, the skin does not need to be removed, so Apple overrrides this fuction and returns "Skin does not need peeled".

Now say you add an Apple to your FruitBasket. Then you call PeelSkin() on FruitBasket[0].

Since it is a basket of Fruit Objects, you might expect to get "Skin removed from fruit, now ready for eating", BUT you will actually get the correct message "Skin does not need peeled". That is polymorphism in action.

saratoga
07-20-2005, 08:45 PM
High level overview:

http://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29