Ada 95 Quality and Style Guide Chapter 4
Proper structure improves program clarity. This is analogous to
readability on lower levels and facilitates the use of the readability
guidelines (Chapter 3). The various program structuring facilities
provided by Ada were designed to enhance overall clarity of design.
These guidelines show how to use these facilities for their intended
purposes.
The concept of child packages supports
the concept of subsystem, where a subsystem is represented in
Ada as a hierarchy of library units. In general, a large system
should be structured as a series of subsystems. Subsystems should
be used to represent logically related library units, which together
implement a single, high-level abstraction or framework.
Abstraction and encapsulation
are supported by the package concept and by private types. Related
data and subprograms can be grouped together
and seen by a higher level as a single entity. Information
hiding is enforced via strong typing
and by the separation of package and subprogram specifications
from their bodies. Exceptions and tasks are additional Ada language
elements that impact program structure.
Well-structured programs are easily understood, enhanced, and
maintained. Poorly structured programs are frequently restructured
during maintenance just to make the job easier. Many of the guidelines
listed below are often given as general program design guidelines.
4.1.1 Separate Compilation Capabilities
guideline
guideline
guideline
guideline
guideline
guideline
guideline
guideline
guideline
guideline
Ada's ability to enforce information
hiding and separation of concerns
through its visibility controlling features is one of the most
important advantages of the language, particularly when "pieces
of a large system are being developed separately." Subverting
these features, for example, by excessive reliance on the use
clause, is wasteful and dangerous. See also Guidelines 5.7 and
9.4.1.
4.2.1 Minimization of Interfaces
guideline
rationale
guideline
guideline
guideline
rationale
This section addresses the issue of exceptions in the context
of program structures. It discusses how exceptions should be used
as part of the interface to a unit, including what exceptions
to declare and raise and under what conditions to raise them.
Information on how to handle, propagate, and avoid raising exceptions
is found in Guideline 5.8. Guidelines on how to deal with portability
issues are in Guideline 7.5.
4.3.1 Using Exceptions to Help Define an Abstraction
guideline
high-level structure
4.1 HIGH-LEVEL STRUCTURE
example
rationale
example
example
example
example
example
example
rationale
example
4.2 VISIBILITY
example
example
example
example
4.3 EXCEPTIONS
example
4.4 SUMMARY
visibility
exceptions
In This Guide:
Table of Contents
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Appendix
References
Bibliography
Index