EGL packages

Packages organize source files and prevent naming conflicts.

A package is a named collection of related parts; think of a package in the same way as you think of a folder or directory on your local system.

Packages prevent name conflicts by separating files into different contexts. Two parts with the same name cannot be defined in the same package, but two different packages can each have a part with the same name. To prevent conflicts between packages, do not create packages with the same names, even if those packages are in different projects or source folders.

The parts in an EGL source file belong to the same package. The package statement in the file, if any, specifies the name of that package. If you do not specify a package statement, the parts are stored in the root of the source folder and are considered to be in the default package. If you do not specify a package statement, files in the default package cannot be shared by parts in other packages or projects.

Package names are case sensitive. For more information about naming conventions for packages, see the "package" reference topic.

When you want a part to reference another part that is in the same package, you do not need to specify the location of the second part. The following example shows two parts in the same package: a Record part and a Program part that uses the record part:
package com.companyb.firstpackage;

program testProgram type BasicProgram
    function main()
        myVariable myRecordPart;
    end
end

Record myRecordPart type BasicRecord
    field1 int;
    field2 string;
end
When you want a part to reference another part that is in a different package, specify the complete location of the part within its package. For example, the following Program part uses the Record part from the previous example:
package com.companyb.secondpackage;

program testProgram2 type BasicProgram
    function main()
        myVariable2 com.companyb.firstpackage.myRecordPart;
    end
end

To cause EGL to use the part in the source file, use the import statement. If you import a part in this way, you can use the part as though it were in the current package, without specifying the complete location of the part within its package each time you use it. Importing a part in this way is sometimes called "bringing the part into scope."

For example, the following Program part again uses the Record part defined earlier, but this time it imports the part first:
package com.companyb.thirdpackage;

import com.companyb.firstpackage.myRecordPart;

program testProgram3 type BasicProgram
    function main()
        myVariable3 myRecordPart;
    end
end
Note that the import statement uses the package path to the part and the part name, not the source file name.

For more information about import, see “Writing import and use statements.”


Feedback