23B. Standards for Modules

The interface of a module consists of all of the things that it exports. Ideally, only things that are exported by A.cpp are written in A.h. Unfortunately, that is not always possible; you will occasionally find that you need to put information in a header file that is not part of the interface.

That typically happens with types. In order to export a type definition, you will usually need to provide information about the type that is not intended to be exported. For example, the fact that type T is a pointer type is probably not relevant to other modules. We will see structures shortly. Variables that belong to structures are usually not exported, even when you write them in header files.

Keeping that in mind, follow the following standards when writing modules and header files.

Do not unnecessarily write information about nonexported things in header files.

Do not write in header files prototypes for functions that are not exported.

Do not bypass the interface to a module [Violate interface: 10-20 points]

When module B.cpp includes A.h, B.cpp must only use things described in A.h that are really in the interface of A.cpp.

This is particularly important when a module implements an abstract data type.