|
|
*
|
|
a simple example is used to illustrate the design and
implementation of modules.
This example is based on a stack of integers
we want a module to produce a stack of integers.
There may be multiple instances of these stacks
in this case a module encapsulates a data structure
and the functions that are used to manipulate it
the data structure is hidden in the module, it is only
visible to the module's functions, other functions can
only manipulate it by calling stack module functions
we view the stack module as a state machine, at any
point in time each stack is in a particular state. The
module's functions are used to move the stack from
one valid state to another
how do we design a module? One approach is to list
the operations that we would like to perform, this
works well with our example
since we can have multiple stacks, we need functions
to create and destroy stacks. In addition we will need
routines to push and pop from the stack
In addition to this basic functionality, we need a few
functions that return the stack's state, functions for
testing whether the stack is full or empty, and one for
peeking at the top element of the stack
|
|