10.3 Separate construct
In order to provide reuser with maximum flexibility, and to manage large components easily ( Known as programming-in-large), define subunits as separate to develop independently. It allows you to split the module into more smaller and independent unit which is known as "Top-down design methodology". In Ada, a package body, subprogram specification, and task body can be declared as separate.
Ada allows, subunits for the separate compilation of the proper body of a program body of a program unit declared within another compilation unit. A body stub is only allowed as the body of a program unit which is a subprogram, a package, a task unit, or a generic unit. The designer can provide reuser with such subunits which are system dependant and to reuse other components more efficiently. See the following example for the use of separate construct.
package Syntax_Analyser is
type Lexeme is private;
-----------------
function Lexical_analyser return Lexeme;
procedure Error_handling( Message : String);
procedure Parse( T : Token);
procedure Semantic_Actions ( Action : Token);
end Syntax_Analyser ;
Package body Syntax_Analyser is
function Lexical_analyser return Lexeme is separate;
procedure Error_handling( Message : String) is separate ;
procedure Parse( T : Token) is separate is separate;
procedure Semantic_Actions ( Action : Token) is separate;
end Syntax_Analyser ;
In this example, the subunit Lexical_analyser is a language dependant, in order to reuse other modules it is advisable to allow the reuser to provide the implementation for a desired language. In order to develop these subunits independently then declare as follow.
separate ( Syntax_Analyser )
function Lexical_analyser return Lexeme is
begin
----------------
end Lexical_analyser;
Guideline1 : Always use separate construct whenever a package is defined so
that it provides reuser to develop package body, and subprograms
independently which promotes reuse of specifications.