2.15 Chapter 2 Summary

[ Table of Contents ] Prev ] Chapter Overview ] [ Glossary/Index ]

As usual, we begin with some self-test questions.  (Answers are listed below in reverse order.)

Self-Test Questions
Click Q#-# to see answer

Q2-1 What are the six kinds of program unit in Ada?
Q2-2 Which of the six kinds of program unit can be library units?
Q2-3 What are the three kinds of relationships used to "connect" program units?
Q2-4 What is the difference between a library unit and a compilation unit?
Q2-5 What are the different ways of nesting a subprogram in a package?
Q2-6 What does ADT stand for, and what is an ADT package?
Q2-7 Why might you want to create a generic package?
Q2-8 Why might you want to create a subunit?

Key points of this chapter

Self-Test Answers

A2-8 A subunit is compiled separately from its logically-enclosing package. Therefore, it can be re-compiled or replaced by another version with the same name, without having to modify or re-compile the enclosing unit and other units that depend upon it.
A2-7 Generic packages provide powerful support for reuse. For example, a generic package can provide a "parameterized class of objects" that can be instantiated in a number of useful ways, without having to re-write the internal logic of the methods associated with the class.
A2-6 ADT stands for "abstract data type." An ADT package defines a data type in such a way that client modules can create instances of the type and call its operations, but cannot gain access to the inner workings as defined in the private part of the package specification or the package body.
A2-5 A subprogram can be nested in a package in one step, by simply including the subprogram body inside the package body. Alternatively, it can be nested in two steps, by declaring the subprogram in the package declaration, and then including the subprogram body inside the package body. The latter method makes the subprogram available to clients of the package.
A2-4 Typically, a compilation unit is some source text that begins with one or more context clauses, followed by the text defining a library unit body or library package declaration or separate subunit. If no context clauses are needed, a compilation unit may be simply the text defining a library unit body or library package declaration.
A2-3 Withing relationships, parent/child relationships, and nesting relationships are used to connect program units.
A2-2 Only subprograms, packages, and generic units can be library units.
A2-1 The six kinds of program units are: subprograms (procedures and functions), packages, generic units, tasking units, protected units, and protected entries.

[ Click here to return to questions ]

Wrap-up Discussion

You have seen a number of examples of how program units can be connected together to form programs. Key terms included in the Glossary/Index are:

abstract data object (ADO) abstract data type (ADT) body
child unit compilation unit declaration
generic unit hierarchical library library unit
nested unit package private part
program unit protected unit subsystem
subprogram subunit task
with clause

The next chapter focuses on various kinds of executable statements.

[ Back to top of pagePrev ] [ To next chapter ]