5.1: Data Abstraction Revisited

The first step in creating a program is to develop the algorithm that will produce the solution. The algorithm must detail operations that will be performed on the given data. A decision must also be made about how the data will be organized. Typically data is best split into distinct groups, or collections, based on the basic operations required for each collection. The data structure utilized for each collection can be tailored to the specific operations to be performed on it. Each collection, with its operations, can then be treated individually as a data abstraction.

A data abstraction is a collection of data upon which only a set of specific operations are allowed. The technique of data abstraction has been used in this text as a tool in creating programs that are understandable and maintainable. Insight is required to determine the particular collection to use and the operations to act upon it. The same collection may be useful in a number of different problems. This may be so with the same set of allowable operations or with different sets of operations. As an example, recall that the stack data abstraction was used in both towers and next with the same operations.

Once the data abstractions to be used in a solution are determined, a decision must be made on how to implement them. This requires deciding what data structure is to be used to store the collection and how the operations on it will be defined. In this text each operation has been incorporated in a function using the tool of functional modularization. Treating the collection and its operations as a data abstraction means that the program can only process the collection using those functions. This guarantees that the collection is accessed only when one of the functions is invoked. Proper packaging of the data abstraction can thus ensure that it is used appropriately. How this packaging is done is the topic of this chapter.

The discussion is presented only now for several reasons. First, preceding chapters have introduced a number of data abstractions that can serve as vehicles to present different approaches to packaging. Next, packaging introduces another level of abstraction, which can complicate the understanding of the basic material. Time was needed to absorb the beginning concepts. Finally, packaging is language-dependent, and the aim of this book is to be as language-independent as possible yet still present programs in the C programming language. Given the language-dependence of packaging and the belief that students should first concentrate on basics, the topic is confined to this chapter. This does not mean it is unimportant梠nly that it might cloud the other concepts presented. Consequently the material in this chapter may be skipped or, alternatively, imposed on the programs in the later chapters. The C approaches to packaging are straightforward; should you desire, the programs can be readily modified to the style presented here.