9.1 Importing components

The library units can be imported using with & use clauses, and generic units can be instantiated using new construct as shown below. The with clause known as context clause is used to specify the library units whose names are needed within a compilation unit. The use clause achieves direct visibility of declarations that appear in the visible parts of named packages. But there is a danger of naming conflicts with use clause when importing more than two packages with similar names.

An instance of a generic unit which means a derived and immediate copy of generic units and it is declared by a generic instantiation using new construct in Ada. Ada allows you instantiate to create such copies of generic packages with proper supply of actual parameters, generic procedures, generic functions. This supports software development methodology, and reuse of components.

with Text_IO, Table_Manager, Lists;

use Text_IO, Table_Manager, Lists;

procedure New_Table is

---- This package is imported from the library package Text_io ----

Package Int_IO is new Integer_IO ( Integer ); --- instantiation

--------------

Table_Manager.Insert ( I, T );

Lists.Insert( E, L );

Int_IO.put ( I );

---------------

end New_Table;

Guideline1 : Always use dot notation to avoid naming conflicts when importing library units.

Guideline2 : Always documentation using comment statements should be provided with necessary informations whenever a component is imported.

But the above has still limitations because it is not advisable to import with use constract, see the following rename construct for better alternative.