Class Responsibility (CR)
Overview
The
Class Responsibility metric provides the degree of responsibility of a class or a package.
For
a class (and respectively for a package), it gives the percentage of operations that
include pre or post-conditions, with regard to the number of operations that the class (and respectively
the package) has.
Computation
![]()
|
The ... variable |
represents the … |
|
PCC |
number of operations which implement
pre-condition contracts |
|
POC |
number of operations which implement
post-condition contracts |
|
NOM |
number of operations |
Nominal range
Between
20 % and 75 %
Analysis
The
application is more robust if classes check the conditions of use for their
services and their returned results.
However, too many checks can introduce a certain encumbrance which is
not necessarily needed.
The
fewer pre and post-conditions there are on the operations of a class, the more
the class will be similar to a group of functions, rather than a consistent set
of operations.
The
robustness and the re-use of components which use pre and post-conditions will
be increased.
Certain
operations that only read attributes will not have pre and
post-conditions. This explains why the
upper limit of 100% is very rarely reached.
A
value of less than 20% is more alarming than a value greater than 75%.