Previous: Complexity Metrics Control, Up: Specifying a set of metrics to compute Object-Oriented Metrics Control

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.

A class K's efferent coupling is the number of classes that K depends upon. A category's efferent coupling is the number of classes outside the category that the classes inside the category depend upon.

A class K's afferent coupling is the number of classes that depend upon K. 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 (if any) is considered together with its spec when counting the dependencies. 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:

Report all the coupling metrics
Do not report any of metrics
Report package efferent coupling
Do not report package efferent coupling
Report package afferent coupling
Do not report package afferent coupling
Report category efferent coupling
Do not report category efferent coupling
Report category afferent coupling
Do not report category afferent coupling