Next topic |
Ada Home Page |
Index
Packages
Package
- collection of resources
- encapsulated in one unit
- single library unit
Examples:
Used for:
- collection of types and constants
- group of related subprograms
- user defined types and allowable operations
Benefits of packages:
- information hiding
- reuse
- abstract data types
- simpler programming
Package Organisation
- Package specification
shows "what" it provides
- Package body defines
"how" it is implemented.
- Both are separate from the user's program that uses the package.
Visibility
Compilation commands
Compilation order (separate compilations):
- package specification
- package body
- program that uses package
Example
An example
shows the organisation of a package of routines for working with rectangles,
circles, etc, and a program that makes use of the package.
Developing packages
- contents?
- collection of types and constants
- related subprograms
- user defined type and operations
- specification
- interface for each operation
- publicly-visible types, constants, (variables)
- type implementations: private
- file name:
- sun ada: pack_s.a
- gnat ada: pack.ads
- body
- subprogram code
- extra declarations as needed
- file name:
- sun ada: pack_b.a
- gnat ada: pack.adb
Next topic |
Ada Home Page |
Index
c-lokan@adfa.oz.au / 20 Feb 96