figure
area,
perimeter
readFigure |
computeArea |
computePerim |
displayFig |
circle square rectangle
readFigure |
|
readFigure |
|
readFigure |
computeArea |
computeArea |
computeArea |
||
computePerim |
computePerim |
computePerim |
||
displayFig |
displayFig |
displayFig |
Inheritance: The classes circle, square, and rectangle are derived from the class figure.
A
polymorphic variable: The pointer
variable myFig in the main function of
the file figureTest.cpp can point to objects of
the classes circle, square, or rectangle.
Polymorphism and dynamic
binding of methods: The methods
associated with the classes circle, square, or rectangle
can all be invoked through myFig dynamically.
When the object currently pointed to by myFig is of a specific class, the
methods associated with that specific class are invoked.
Adtvantage of polymorphism and
dynamic binding: contrasting with a program that processes graphic
objects from the three classes circle, square, or rectangle,
but deal with them as three independent classes.