13.6 Nested Generics
For a generic component with a long generic parameter list, it is possible to instantiate by supplying actual parameters, but which rather difficult. For subprograms and constant object parameters, it is possible to shorten the actual parameter list by specifying default values. But it is not possible to specify defaults for type and variable object parameters. In order to overcome this difficulty, specify formal parameters as a nested generic. See the following example of a Message_Manager.
generic -- package Message_Manager
type Message_kind is ( <> );
Package Message_Manager is
generic -- procedure Send
type Message is private;
type Object_Id is private;
with function String_To_Message ( The_string : in String ) return Message;
procedure Send ( The_message : in Message; From : in Object_Id; To : in Object_Id; Acknowledge : in Boolean );
generic -- procedure Receive
type Message is private;
type Object_Id is private;
with function String_To_Message ( The_string : in String ) return Message;
procedure Receive ( The_message : in Message; From : in Object_Id; To : in Object_Id; Acknowledge : in Boolean );
function Kind_Of_Message return Message_kind;
Transmission_Error, Reception_Error : Exception;
end Message_Manager;
Guideline1 : When a generic component has too many ( say more than three ) formal parameters, specify the component as a nested generic which promotes layers of abstraction.