9.1 Subprogram Interface Design
Package mechanism in Ada consists of interface description of the subprograms.
Designing interfaces for reusable components are depending on parameterization, and design of ADT's. In other words, interface design is directly related to the design of ADT's. Similarly, there are several parameterization styles related to interface design [Braun, Goodenough 85] & [Tracz 90]. These include the following.
* naming conventions,
* use of global data,
* types and number of parameters, and
* use of functions or procedures.
Look at the following example of a Deque package with poor interface design over the basic operations such as Push, Pop, and Directions( Front, Rear).
package Deque1 is
----- declare Element_type and Deque_type
procedure Push_Front ( Value : in Element_Type; Dq : in out Deque_Type);
procedure Push_Rear ( Value : in Element_Type; Dq : in out Deque_Type);
procedure Pop_Front ( Value : in Element_Type; Dq : in out Deque_Type);
procedure Pop_Rear ( Value : in Element_Type; Dq : in out Deque_Type);
procedure Print ( Dq : in Deque_Type );
end Deque1;
Alternatively, if we design by reducing the number of interfaces, with increase in the number of parameters as follow.
package Deque2 is
----- declare Element_type and Deque_type
type Location_Type is ( Front, Rear );
procedure Push ( Value : in Element_Type; Dq : in out Deque_Type; Direction : in Location_type := Front );
procedure Pop ( Value : in Element_Type; Dq : in out Deque_Type
Direction : in Location_type := Front );
procedure Print ( Dq : in Deque_Type );
end Deque2;
Consider the following guidelines for the subprogram interface design.
Guideline1 : Decide on the trade off between the number of interfaces, and the number of parameters. This means that there should not be too many number of parameters as well as the number of subprograms.
Guideline2 : For all Formal parameters with in the interface definitions, always define the mode as "in out" instead of "out" .
Guideline3 : Initialize as default value for formal parameters of enumerated types within the interface itself as shown in the above example,
Direction : in Location_type := Front .