Contents > B: List of Design Metrics > B.3 Package Metrics

B.3 Package Metrics

Metric: NumClsCategory: Size
The number of classes in the package.

Counts all classes, regardless of their visibility (public, protected, private, or package), or abstractness.


Metric: NumCls_tcCategory: Size
The number of classes in the package, its subpackages, and so on.

This is the sum of metric NumCls for this package, and all its direct and indirect subpackages.


Metric: NumOpsClsCategory: Size
The number of operations in the classes of the package.

This is the sum of metric NumOps, taken over all classes in this package, and more fine-grained measure of the size of the package.


Metric: NumInterfCategory: Size
The number of interfaces in the package.

Like metric NumCls, this counts all interfaces, regardless of their visibility.


Metric: RCategory: Complexity
The number of relationships between classes and interfaces in the package. There is a dependency from class or interface C to class or interface D if
  • C has an attribute of type D
  • C has an operation with a parameter of type D
  • C has an association, aggregation, or composition with navigability to D
  • C has a UML dependency or usage dependency to D
    UML dependencies are shown as dashed arrows in the diagrams (usage with stereotype 'use').
  • C is a child of D
  • C implements interface D
The metric counts all such dependencies between classes and interfaces in the package. Bidirectional associations are counted twice, because C knows D and vice versa. By convention, associations that indicate no navigability at either end are considered to be bidirectional.


Metric: HCategory: Cohesion
Relational cohesion.

This is the average number of internal relationships per class/interface, and is calculated as the ratio of R+1 to the number of classes and interfaces in the package.


Metric: CaCategory: Coupling (export)
Afferent coupling.

The number of elements outside this package that depend on classes or interfaces in this package. The dependencies considered are the same ones listed with metric R.


Metric: CeCategory: Coupling (import)
Efferent coupling.

The number of elements outside this package that classes or interfaces in this package depend on. The dependencies considered are the same ones listed with metric R.


Metric: ICategory: not specified
Instability or ease of change.

This is the ratio of efferent coupling (metric Ce) to total coupling (Ce+Ce). Values of metric I range between 0 and 1.

A value close to 0 indicates a package that does not rely much on other packages, but is heavily relied upon by other packages. Such a package should be stable, because it is hard to change: changes to the package potentially have a large impact on the model ("ripple effects").

A value close to 1 indicates a package that mostly relies on other packages, but that itself is not much relied upon. Such a package can be unstable, because it is easy to change: changes to the package are not likely to have a large impact on the model.


Metric: ACategory: not specified
Abstractness (or generality) of the package.

This is the ratio of abstract classes and interfaces in the package to the total number of interfaces and classes in the package.

Values range from 0 to 1. Zero indicates packages without interfaces or abstract classes, 1 indicates a package consisting only interfaces and abstract classes.


Metric: DCategory: not specified
Distance from the main sequence. Package design should aim to strike a balance between instability and abstractness of the packages. A stable package should be abstract, so that changes to the package are merely extensions that do not affect existing clients of the package. An unstable package is easy to change and can therefore be concrete.

The Stable-Abstractions-Principle (SAP) says that a package should be as abstract as it is stable. With abstractness measured by metric A, and stability measured by metric I, the SAP demands that A+I be close to 1.

If you plot A vs. I in a graph, the "main sequence" is the theoretical optimal line where A+I=1. Metric D is the distance of the package from the main sequence, and is calculated as (A+I-1)*sqrt(2).

Values range from -sqrt(2) to +sqrt(2). Values close to zero indicate packages that adhere to the SAP. A large negative value indicates a package that is concrete and stable (A and I close to 0). Such a package can be "painful" because it is not extensible and prone to change. A large positive value indicates a package that is abstract and unstable. Such a package is extensible but has few dependents, and is therefore useless.


Metric: DNCategory: not specified
Normalized distance D' from the main sequence.

This is a variation of metric D that has been normalized to range between 0 and 1. It is calculated as |A+I-1|. Values close to zero indicate packages that adhere to the SAP (see metric D).


Metric: NestingCategory: Nesting
Nesting level of the package in the package hierarchy.

Top level packages have nesting level 0, their subpackages are at level 1, and so on.


Metric: ConnCompCategory: Cohesion
The connected components formed by the classes and interfaces of the package.

The classes and interfaces of a package, and their dependencies, form a graph. This metric counts the number of connected components of that graph.

Ideally, all classes and interfaces of the package should be related directly or indirectly, so that there is only one connected component. If there are two or more connected components, you may consider moving some classes or interfaces to other packages, or splitting up the package.

  • See metric R for the list of dependencies considered between the classes and interfaces.
  • The graph considered is an undirected graph, directions of dependencies are ignored.
  • You can view the connected components in the Graph Structures View.


Metric: Dep_OutCategory: Coupling (import)
The number of UML dependencies where the package is the client.

See also Dep_Out for classes.


Metric: Dep_InCategory: Coupling (export)
The number of UML dependencies where the package is the supplier.

See also Dep_In for classes.


Metric: DepPackCategory: Coupling (import)
The number of packages on which classes and interfaces of this package depend.

A package P depends on a package P' if

  • a class or interface in P depends on a class or interface in P' (see metric R for a description of these dependencies).
  • there is a UML dependency (dashed arrow) from P to P'.
The more packages P depends on, the more difficult it is to reuse P in a different context.

This metric is similar to metric Ce, the difference is that Ce counts the individual classes or interfaces that are depended upon.


Metric: MsgSent_OutsideCategory: Coupling (import)
The number of messages sent to instances of classes outside the package.

The metric counts, for instances of classes of this package, the messages they send to instances of classes from other packages. That is, outgoing messages that cross the package boundary. Note that messages to unclassified instances are not counted here.


Metric: MsgRecv_OutsideCategory: Coupling (export)
The number of messages received by classifier instances of classes outside the package.

The metric counts, for instances of classes of this package, the messages they receive from instances of classes from other packages. That is, incoming messages that cross the package boundary. Note that messages from unclassified instances are not counted here.


Metric: MsgSent_withinCategory: Complexity
The number of messages sent between classifier instances of classes in the package.

The metric counts, for instances of classes of this package, the number of messages they send to themselves or other instances of classes from this package. Note that messages to unclassified instances are not counted here.


Metric: DiagsCategory: Diagram
The number of times the package appears on a diagram.