3 - Programming in the Large
Published online by Cambridge University Press: 05 October 2015
Summary
DeRemer and Kron (1975) distinguished the activities of writing large programs from that of writing small programs. They considered large programs to be systems built from many small programs (modules), usually written by different people. It is common today to separate the features of a programming language along the same lines. In Chapter 2, we presented the aspects of Ada required to write the most basic programs. In this chapter, we discuss some of Ada's features that support the development of large programs.
To facilitate the construction of large programs, Ada makes use of programming units. An Ada program consists of a main subprogram that uses services provided by library units. A library unit is a unit of Ada code that we may compile separately. Library units are often called compilation units. We have already made use of many predefined library units in our examples. The with clause provides access to a library unit. The use clause provides direct visibility to the public declarations within a library unit so we do not have to prefix them with the name of the library unit.
A library unit is a subprogram (a procedure or function), package, or generic unit. The main subprogram is itself a library unit. Subprograms, packages, and generic units that are nested within another programming unit are not library units; they must be compiled with the programming unit in which they are nested. Generally, we use a compiler and linker to create an executable from a collection of library units. Library units also play a role in mixing Spark and non-Spark code in a single program – a topic we discuss in Chapter 7. In the following sections, we will introduce you to the package and to generic units.
Encapsulation and information hiding are the cornerstones of programming in the large. Both concepts deal with the handling complexity. There are two aspects of encapsulation: the combining of related resources and the separation of specification from implementation. In object-oriented design and programming, we use encapsulation to combine data and methods into a single entity called a class. Encapsulation also allows us to separate what methods a class supplies for manipulating the data without revealing how those methods are implemented.
- Type
- Chapter
- Information
- Building High Integrity Applications with SPARK , pp. 68 - 98Publisher: Cambridge University PressPrint publication year: 2015