An Access type is called pointer in some other programming languages. In Ada, an access type is to designate an object, the access value is returned by an allocator, and it is defined as follows.
type Linked_List_Pointer is access Linked_list_type;
In order to design for reuse, it is advisable to declare an access type recursively with an incomplete type declaration as shown below.
Package Lists is
type Element is .....;
type Linked_List_Pointer is limited private;
procedure Insert ( X : in Element );
--------------------
procedure Display;
private -- access type defined recursively
type Linked_list_type;
type Linked_List_Pointer is access Linked_list_type;
end Lists;
For Data-Structure components, it is possible to elaborate the incomplete type into a record type which is a composite type. See the following example of a Linked-List structure.
Package body Lists is
type Linked_list_type is
record
Value : Integer;
Next : Linked_List_Pointer;
Previous : Linked_List_Pointer;
end record;
-------------------------
end Lists;
But one must be careful to reference the particular object. In order to design for reuse for abstract data-structure components then it might be helpful to follow the following guidelines.
Guideline1 : Define the structure-type recursively, combination of an incomplete type and an access type in order to hide the detailed implementation of structures (information hiding principle).
Guideline2 : Defer the detailed implementation of structures into package body . This means elaborate the incomplete type in the package body which was defined in the private part of the specification. This promotes the reuse of specifications and principles of information hiding.
Guideline3 : To create lists of objects dynamically define as follow.
Head : Linked_List_Pointer := new Linked_list_type'(0, null, null);