How Does Polymorphism Help?
By replacing switch statements with a polymorphic call we improve dramatically the decoupling between caller and callee.
Shape
Rect
draw()
toString()
setText()
draw()
setOrigin()
setColor()
Oval
draw()
toString()
setText()
Line
draw()
toString()
setText()
while …
ChooseShape(shape) ;
case shape of..
1 : DrawRect();
2 : DrawOval();
3 : …
endcase
endwhile
while …
Shape sh=chooseShape();
sh.draw();
endwhile
Previous slide
Next slide
Back to first slide
View graphic version