Polymorphism deals with abstract classes, where a virtual method is defined, but an implementation is not provided. It is up to the derived concrete class to provide the implemenation, which could vary widely from derived class to derived class.
A client program calls the virtual method, but the functionality executed will vary depending upon the concrete class implementing the abstract interface being used.
The classic example is the abstract class Shape, used in a graphical design program. Many real shapes are derived from it, such as, Circle, Square, Rectangle and Line. Shape defines the abstract draw() method, but each derived class has to provide the implementation, which will vary for each of the above.
Now the set of Shapes in a picture can be drawn with a method that looks like of like the following...
Picture::draw()
{
for each shape in Shape...
shape.draw()
}
If Picture contains all circles, then only Circle::draw() will be called. If it contains all squares, then only Square::draw() will be called, If the Picture contains a mixture of shapes, then each unique draw() method will be called.
If new shape is added, Picture::draw() doesn't need to be changed.
2006-06-18 15:00:33
·
answer #1
·
answered by MarleyTheCat 3
·
0⤊
0⤋
"Polymorphic calls are programming language constructs that enhance a programmer’s ability to organize behavior"
For a full description, see: .http://www.cs.mcgill.ca/~karel/efficient.polymorphic.calls.pdf
This is a pdf file. Use the search terms, Polymorphic calls are
to get the details, or read the entire document. There is a picture example included.
2006-06-17 23:27:21
·
answer #2
·
answered by Seikilos 6
·
0⤊
0⤋
A polymoprphic call allows related objects to respond differently to the same method.
2006-06-18 09:53:10
·
answer #3
·
answered by ♣volatility♣ 4
·
0⤊
0⤋