-*- Mode: Text; Fonts: Ct18b -*- 13.1 THE FORM OF ADA PACKAGES A package forms a collection of logically related entities or computational resources. Formally, we say that a package encapsulates (puts a wall around) these resources. In Chapter 6, we introduced the symbol for an Ada package, repeated herein Figure 13-1. From this figure we see that a package consists of two parts, the specification and the body. The specification identifies and describes the visible parts of the package; formally, the package exports these entities. We have used two different symbols in the package specification to distinguish between exporting objects and type (the rounded rectangle)and exporting operations (the regular rectangle). In a sense, this package specification is the contract between the implementer of the package and the user. This interface specifies which parts of the package may be used and, furthermore, how they may be used. It is not important for a user to understand how these operations are actually implemented. In addition, a package user may refer only to these visible entities. For example, the human interface to a car includes the steering wheel, brakes, and accelerator; these are the resources that are visible. The driver doesn't need to know how these resources work-that's an implementation detail. In Ada, similar details can be hidden in the package body. This structure directly supports the principles of modularity, abstraction, localization, and information hiding. Of course, good programmers can apply these principles in other languages, including FORTRAN or even assembly languages. The difference between Ada and most other programming languages is is that Ada packages enforce and encourage these principles. The language rules do not permit a package user to do anything more than what the package specification allows. If the user tries, he or she will be trapped at compilation time with syntax errors. Since the specification and body may be separately compiled, it is a simple matter to create the specification early in the software design and then add the body later. Furthermore, it is good practice to separate the two parts physically-supporting information hiding literally. Perhaps most importantly, though, Ada packages help the programmer control the complexity of software solutions by giving him or her a mechanism with which to physically group related entities into a logical chunk.