OOMetrics

Object Oriented Systems Metrics

An IPA Project
... Under Construction ...
Critique this page via E-mail

*Definitions
*Metrics
*Guidelines
*Bibliography

Definitions

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.

Metrics

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

Weighted Methods per Class (WMC)

Definition

WMC is the sum of the complexity of all methods for a class.

Viewpoints

  1. 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.
  2. 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.
    1. Con: But children can ignore much of the functionality, and programmers do ignore it during design.
    2. Pro: Subclassing does require regression testing on the parent, since a child could have hosed up a relationship between parent classes.
  3. Classes with large numbers of methods are likely to be more application specific, limiting the possibility of reuse
    1. Con: numbers vs unnecessary numbers
    1. Con: what about abstract classes?

Discussion

There is a difference between complexity and appropriate complexity. Only when the two are confused is there trouble.

Depth of Inheritance Tree (DIT)

Viewpoints

  1. 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.
  2. Deeper trees constitute greater design complexity, since more methods and clases are involved.
  3. The deeper a particular class is in the hierarchy, the greater the potential reuse of inherited methods.

Number of Children (NOC)

Viewpoints

  1. The greater the number of children, the greater the reuse, since inheritance is a form of reuse.
  2. 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.
    1. Con: Simon's watchmaker story
  3. 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.
    1. Con: This viewpoint seems to be pro-depth

Coupling between object classes (CBO)

Viewpoints

  1. 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.
    1. Q: How to define "excessive?"
    2. Con: certain sets of classes need to be clustered.
  2. 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.
  3. 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"...

Response For a Class (RFC)

Viewpoints

  1. 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.
  2. The larger the number of methods that can be invoked from a class, the greater the complexity of the class.
  3. A worst case value for possible responses will assist in appropriate allocation of testing time.

Lack of Cohesion in Methods (LCOM)

Viewpoints

  1. Cohesiveness of methods within a class is desirable, since it promotes encapsulation.
  2. Lack of cohesion implies classes should probably be split into two or more subclasses.
  3. Any measure of disparateness of methods helps identify flaws in the design of classes.
  4. 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 (INTP)

Internal privacy refers to the use of accessor functions even within a class. (For an example, see previous code).

Viewpoints

  1. Constraints are easier to maintain if there is only one access path to a variable
  2. Pre- and Post- code requires strict sequence of access

Discussion


Category Naming (CATN)

Category naming divides classes into semantically meaningful sets.

Viewpoints

  1. Helps in design by giving template as guide
  2. Helps IR

Discussion


Guidelines

Visual Works encourages the use of accessor functions even within the class.

Bibliography

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