OOMetrics
Object Oriented Systems Metrics
An IPA Project
Critique this page via
E-mail
Definitions
Metrics
Guidelines
Bibliography
- Method Complexity
-
- Object Complexity
-
- Coupling
- "two objects are coupled if and only if at least one of them acts upon the
other, X is said to act upon Y if the history of Y is affected by X, where
history is defined as the chronologically ordered states that a thing
traverses in time" [Vessey, Weber 1984]
Two classes are coupled when methods declared in one class use methods or
instance variables of the other class.
[Chidamber, Kemerer 1994, p. 479]
- Cohesion
- What superglue has that a post-it note doesn't.
- Depth of Inheritance
- In Multiple Inheritance, it's the longest tree
- Number of Children
- The count of immediate descendents
- Response Set
- the set of all methods that can be invoked in response to a message sent
to an object of a class.
The following metrics and viewpoints are taken from Chidamber & Kemerer 1994
Metrics Quick Guide
- WMC
- Weighted Methods Per Class: the sum of the complexities of all methods of
a class.
- DIT
- Depth of Inheritance Tree: in cases of multiple inheritance, the maximum
length from the node to the root of the tree.
- NOC
- Number of Children: the number of immediate subclasses.
- CBO
- Coupling between object classes: the count of the classes to which this
class is coupled.
- RFC
- Response For a Class:
- LCOM
- Lack of Cohesion in Methods
- INTP
- Internal Privacy
- CATN
- Category Naming
Definition
WMC is the sum of the complexity of all methods for a class.
Viewpoints
- The number of methods and the complexity of methods involved is a predictor
of how much time and effort is required to develop and maintain the class.
- The larger the number of methods in a class the greater the potential
impact on children, since children will inherit all the methods defined in the class.
- Con: But children can ignore much of the functionality, and programmers do
ignore it during design.
- Pro: Subclassing does require regression testing on the parent, since a
child could have hosed up a relationship between parent classes.
- Classes with large numbers of methods are likely to be more application
specific, limiting the possibility of reuse
- Con: numbers vs unnecessary numbers
- Con: what about abstract classes?
Discussion
There is a difference between complexity and appropriate complexity.
Only when the two are confused is there trouble.
Viewpoints
- The deeper a class is in the hierarchy, the greater the numbner of methods
it is likely to inherit, making it more complex to predict its behavior.
- Deeper trees constitute greater design complexity, since more methods and
clases are involved.
- The deeper a particular class is in the hierarchy, the greater the
potential reuse of inherited methods.
Viewpoints
- The greater the number of children, the greater the reuse, since
inheritance is a form of reuse.
- The greater the number of children, the greater the likelihood of improper
abstraction of the parent class. If a class has a large number of children, it
may be a case of misuse of subclassing.
- Con: Simon's watchmaker story
- The number of children gives an idea of the potential influence a class has
on the design. If a class has a large number of children, it may require more
testing of the methods in that class.
- Con: This viewpoint seems to be pro-depth
Viewpoints
- Excessive coupling between object classes is detrimental to modular design
and prevents reuse. The more independent a class is, the easier it is to reuse
it in another application.
- Q: How to define "excessive?"
- Con: certain sets of classes need to be clustered.
- In order to improve modularity and promote encapsulation, inter-object
class couples should be kept to a minimum. The larger the number of couples, the
higher the sensitivity to changes in other parts of the design, and therefore
maintenance is more difficult.
- A measure of coupling is useful to determine how complex the testing of
various parts of a design are likely to be. The higher the inter-object class
coupling, the more rigorous the testing needs to be.
Discussion
How to implement this? e.g. "my-object display"...
Viewpoints
- If a large number of methods can be invoked in response to a message, the
testing and debugging of the class becomes more complicated since it requires a
greater level of understanding on the part of the tester.
- The larger the number of methods that can be invoked from a class, the
greater the complexity of the class.
- A worst case value for possible responses will assist in appropriate
allocation of testing time.
Viewpoints
- Cohesiveness of methods within a class is desirable, since it promotes
encapsulation.
- Lack of cohesion implies classes should probably be split into two or more
subclasses.
- Any measure of disparateness of methods helps identify flaws in the design
of classes.
- Low cohesion increases complexity, thereby increasing the likelihood of
errors during the development process.
Discussion
How to count "accessor functions?" i.e.
Object subClass: MyObject
Instance Variables: 'x y'
MyObject methods
x
^x
x: aParm
x := aParm
now... compare
blee: aParm
^self x + aParm
vs.
blee: aParm
^x + aParm
Internal privacy refers to the use of accessor functions even
within a class. (For an example, see previous code).
Viewpoints
- Constraints are easier to maintain if there is only one access
path to a variable
- Pre- and Post- code requires strict sequence of access
Discussion
Category naming divides classes into semantically meaningful
sets.
Viewpoints
- Helps in design by giving template as guide
- Helps IR
Discussion
Visual Works encourages the use of accessor functions even within the
class.
S.R. Chidamber and C.F. Kemerer, "A
Metrics Suite for Object Oriented Design," IEEE Trans. Software Eng.,
vol 20, no 6, June, pp. 476-493, 1994.
I. Vessey and R. Weber, "Research on structured
programming: An empiricist's evaluation," IEEE Trans. Software Eng., vol.
SE-10, pp.394-407, 1984
H. A. Simon, Sciences of the Artificial, MIT Press,
Cambridge, MA, 1981