Unit (programming language Pascal)
A unit is a source code file that is compiled separately . Units have already been introduced in UCSD Pascal (see also Apple Pascal ). One unit consists of a public interface ( interface ) and a private implementation part ( implementation ). They are used to modularize software components and enable the reusability of program parts that are required in different programs.
In the public part, the interface of a unit, types (including classes , constants, variables and routines (functions and procedures)) can be declared. A unit can later be used as a library in other programs via a linker .
example
unit InetTools; // Name der Unit
interface
uses Classes, Windows;
function DownLoadInternetFile(const Source, Dest : String): Boolean;
implementation // ab hier beginnt der ''private'' Teil
function DownLoadInternetFile(const Source, Dest : String): Boolean;
begin
Result := URLDownloadToFile(nil, PChar(Source), PChar(Dest), 0 ,nil) = 0
end;
end.
The unit concept allows the compiler to create a dependency test in the background so that mutual dependencies can be recognized automatically and several units can be compiled at once. If z. For example, if the interface of unit A changes, the compiler has to compile all units that use this unit. If, on the other hand , changes have only taken place in the implementation , only unit A needs to be recompiled.
The foundation stone for the unit concept was laid by Modula-2 in 1982 with the compilation units .