# Weighted Methods per Class

## Contents

Weighted Methods per Class (WMC) is an object-oriented metric to measure complexity in a class. It has been introduced by Chidamber and Kemerer[1].

# Definition

Consider a Class C1, with methods M1,...Mn that are defined in the class. Let c1,...cn be the complexity[2][3] of the methods. Then :

$WMC = \sum ^n_{i=1} c_i$

If all method complexities are considered to be unity, then WMC = n, the number of methods.

# Theoretical basis

WMC relates directly to Bunge's definition of complexity of a thing, since methods are properties of object classes and complexity is determined by the cardinality of its set of properties. The number of methods is, therefore, a measure of class definition as well as being attributes of a class, since attributes correspond to properties.

# 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.

• Classes with large numbers of methods are likely to be more application specific, limiting the possibility of reuse.

Glossary:

Papers:

# References

1. A Metrics Suite for Object Oriented Design
2. Check the Complexity definition in the glossary.
3. Complexity is deliberately not defined more specifically here in order to allow for the most general application of this metric. It can be argued that developers approach the task of writing a method as they would a traditional program, and therefore some traditional static complexity metric may be appropriate. This is left as an implementation decision, as the general applicability of any existing static complexity metric has not been generally agreed upon. Any complexity metric used in this manner should have the properties of an interval scale to allow for summation.