Various dialects of Pascal, such as UCSD Pascal, provide the separate compilation unit, called UNIT, as a half-way measure in the right direction. Unfortunately, the Pascal UNIT facility (interface portion) does not allow a physical separation between specification and implementation, which are tied together in the same compilation unit.
Because the interface section and the implementation section of a Pascal compilation unit are required to be in the same physical unit, the data structure for any Pascal data type must be completely specified in the interface portion except when only one variable of such data type is to be allowed. In such a case the data structure can be hidden in the implementation portion of the compilation unit. This restriction is rather severe. For example, only one complex number variable, only one stack variable, only one string variable, only one list variable, could exist in a program at a given time. This is unrealistic in most cases.
In the Modula-2 dynamic string abstraction presented in section 1.3, each procedure contains a parameter of type string. This permits many string variables to coexist in a program. Each individual string variable may be manipulated independent of the others. The data structure for the type string is not specified in the interface unit (definition module) because of Modula-2’s opaque type facility and the separation between specification and implementation.
To allow each Pascal procedure in the interface portion of a string compilation unit to contain a parameter of type string, the data structure for string must be completely specified before the first parameter reference to type string is given. Thus the essential feature of data hiding is lost in Pascal, even with the limited facility of separate compilation available in some dialects of Pascal.
#pascal #modula-2 #modula #encapsulation #interface