3.4. Packages - JulTob/Ada GitHub Wiki

Package

Basic unit for a collection of logically related entities. Like type declarations and associated operations.

C/C++ | The Encapsulation inside classes is accomplished within packages without the memory wasteful use of objects instantiation.

Portions of a package can be hidden from the user.

A protected unit is the basic unit for defining protected operations for the coordinated use of data shared between tasks. Simple mutual exclusion is provided automatically, and more elaborate sharing protocols can be defined. A protected operation can either be a subprogram or an entry. A protected entry specifies a Boolean expression (an entry barrier) that must be True before the body of the entry is executed. A protected unit may define a single protected object or a protected type permitting the creation of several similar objects.

Although the compilation unit seen contains just a single procedure, most Ada code is in packages. Ada focuses on scalability. As such, is very focused on libraries. So much so, that every subprogram is itself a library unit. These units call services from other libraries. The most common unit is a package, that contains a procedure with the appropriate name.

Print_Root.adb

with Sqrt, Simple_IO;    --Call to libraries

procedure Print_Root is
  use Simple_IO;
  X: float;
begin 
   get(x);
   put(sqrt(x));
end print_root;

Declarations introduce the subject entities. Statements compose the algorithmic action.

Packages

A package is a named container for processes, type definitions, and other entities. Included other packages.

They consist of two parts. Specification and Body.

Specification:

Declares the public entities visible to the rest of the program.

The Interface, and the usage specifications.

Body:

Contains the implementation and private entities that can only be used inside the package.

They can even be compiled separately.

This separation makes it easier for different groups of people to work on design and construction of a program.

To use packages you can use one of the following call techniques:

with Library_Name;
 
Library_Name.Process();
with Library_Path.Child_Library;

Library_Path.Child_Library.Process();

use Library_Path.Child_Library;
...
Process();

package ShortCut renames Library_Path.Child_Library;
...
ShortCut.Process();
subtype ShortType is Library.Object_Type;

procedure Compress(Stuff : ShortType) renames Library.Path.Process;