Information Hiding -- the Problem of Stacks

Here is an example problem that we will use as illustration in the next several slides. Imagine a programming teach containing several indivduals. One programmer is charged with the development of a stack data abstraction. The stack can be characterized by several routines, push, pop, top, and so on. So the programmer dutifully sits down and develops a program, such as the one shown here.

Now imagine that the second programmer wants to use the stack. The second programmer must know of the names for the routines: push, pop, top. But what about the underlying data values; those values used in the implementation of the stack. here these are the array named datastack and the integer value named datatop. These values cannot be local to any single routine, since they must be shared between the different functions. In a language in which procedures are our only abstraction mechanism, the only other choice is to make them global. But this means that the second programmer, the programmer who only wanted to use the stack, must be made aware of the names for these values; if for no other reason then they are not allowed to define other variables with the same name.

Multiply this problem several hundredfold and you see the difficulty of using procedures as an abstraction mechanism.

[audio] [real] Text to accompany slide24, in Chapter 2 of An Introduction to Object-Oriented Programming