In their seminal work on metric for object oriented design, Chidamber & Kemerer defined in 1993 6 metrics, among which the Weighted Methods Per Class (WMC).
Their definition is somewhat ambiguous:
Consider a Class C1, with methods M1,...Mn that are defined in the
class. Let c1,...cn be the complexity of the methods. Then WMC is the
sum of ci for i from 1 to n. .
Defined could mean declared, as in the definition that you have quoted. In this case, you would not count inherited methods. This would make sense because the metric intends to measure how difficult it is to write and maintain the class:
- if a class D would inherit from a base class B, but declare no methods on its own, it is definitively not difficult to maintain. It's certainly easier to maintain, even if B would have 100 methods, than another class that has a couple of methods.
- if a class B would have 10 different constructors, but class D has only 2, the maintenance effort is related to the 2 existing constructors and not to the 10 of the base class.
But defined could also mean available. In this case you should count all the inherited methods. This seems to be the probable interpretation of the authors in their article:
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.
And this can also make sense:
- a high number of methods, even inherited, makes the class more specific and less easy to reuse.
- a high number of inherited methods make the class more difficult to use, and the difficulty to maintain consistency between the many methods could also be higher.
- WMC should be relevant for class semantic (according to C&K), and inherited methods definitively contribute to class semantic.
So you should opt for this second interpretation.
More recent metrics focus more on quality rather than only quantitative impact for maintenance. These are less ambiguous and take into account attributes and methods and make difference between:
- visible and private methods, to measure encapsulation, and
- inherited and available methods, to better take into account the structural benefits of inheritance.