Coupling metrics are object-oriented metrics that measure the dependencies between a given class (or a group of classes) and the “external world” (that is, the other classes in the program). In this subsection the term “class” is used in its traditional object-oriented programming sense (an instantiable module that contains data and/or method members). A category (of classes) is a group of closely related classes that are reused and/or modified together.
K's efferent coupling is the number of classes
K depends upon.
A category's efferent coupling is the number of classes outside the
category that the classes inside the category depend upon.
K's afferent coupling is the number of classes
that depend upon
A category's afferent coupling is the number of classes outside the
category that depend on classes belonging to the category.
Ada's implementation of the object-oriented paradigm does not use the traditional class notion, so the definition of the coupling metrics for Ada maps the class and class category notions onto Ada constructs.
For the coupling metrics, several kinds of modules – a library package, a library generic package, and a library generic package instantiation – that define a tagged type or an interface type are considered to be a class. A category consists of a library package (or a library generic package) that defines a tagged or an interface type, together with all its descendant (generic) packages that define tagged or interface types. For any package counted as a class, its body and subunits (if any) are considered together with its spec when counting the dependencies, and coupling metrics are reported for spec units only. For dependencies between classes, the Ada semantic dependencies are considered. For coupling metrics, only dependencies on units that are considered as classes, are considered.
When computing coupling metrics, gnatmetric counts only dependencies between units that are arguments of the gnatmetric call. Coupling metrics are program-wide (or project-wide) metrics, so to get a valid result, you should call gnatmetric for the whole set of sources that make up your program. It can be done by calling gnatmetric from the GNAT driver with -U option (see See The GNAT Driver and Project Files for details.
By default, all the coupling metrics are disabled. You can use the following switches to specify the coupling metrics to be computed and reported: