Modules in the sense of Modula-2 and Oberon(-2) are used to group related definitions of types, variables, constants, and procedures/functions. In this respect, they are similar to C++ namespaces and Java packages. Furthermore, they support the information hiding principle by allowing to distinguish between the publicly visible interface (consisting of the exported definitions which might be imported by other modules) and the private implementation of a module (which is hidden from other modules).

At run time, modules are initialized in a well-defined linear order that is obtained by traversing the directed acyclic graph defined by their import relationships in a depth-first left-to-right manner (i. e., visiting imported modules in the textual order of their import declarations before visiting the importing module), skipping already visited modules (to avoid that a module is initialized multiple times).

Initialization of a single module means to evaluate initializer expressions of global variables, execute global initializer statements, and activate branches of global virtual functions, in textual order of their appearance.


    module A {
    module B {
    module C {
        import A;
        import B;
    module D {
        import B;
        import C;

Here, the module initialization order will be B, A, C, D.

Christian Heinlein, 22.09.09