This metric measures the number of public methods for each public class.

A class with too many public methods is generally trying to do too much, either at the interface or implementation level or both. It can be difficult for readers to understand because there is a confusing list of operations. Such classes often lack cohesion and are prime candidates for refactoring.

Classes have wide interfaces for a variety of different reasons, and the appropriate fix is different in each case:

  • M. Fowler. Refactoring pp. 65, 122-5. Addison-Wesley, 1999.
  • R. Martin. Agile Software Development: Principles, Patterns, and Practices Chapter 8 - SRP: The Single-Responsibility Principle. Pearson Education, 2003.
  • H. Sutter. GotW #84: Monoliths "Unstrung". Published online, 2002.