Logo Data Structures and Algorithms with Object-Oriented Design Patterns in C++
next up previous contents index

Algorithmic Abstraction

Abstract classes can be used in many interesting ways. One of the most useful paradigms is the use of an abstract class for algorithmic abstraction . The Erase and MoveTo functions defined in Program gif are examples of this.

The Erase and MoveTo functions are implemented in the abstract class GraphicalObject. The algorithms implemented are designed to work in any concrete class derived from GraphicalObject, be it Circle, Rectangle or Square. In effect, we have written algorithms that work regardless of the actual class of the object. Therefore, such algorithms are called abstract algorithms.

Abstract algorithms typically invoke virtual member functions. E.g., the MoveTo function invokes Erase and Draw to do most of the actual work. In this case, the derived classes are expected to inherit the abstract algorithm MoveTo and to override the pure virtual function Draw. Thus, the derived class customizes the behavior of the abstract algorithm by overriding the appropriate member functions. The virtual function resolution mechanism ensures that the ``correct'' member function is always called.


next up previous contents index

Bruno Copyright © 1997 by Bruno R. Preiss, P.Eng. All rights reserved.