Methods is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.
Methods
| Also Known As | Weighted Methods per Class (WMC) |
| API ID | CountDeclMethod |
| Targets | Architectures Classes Files Modules Project |
| Languages | Basic C# C++ Java Pascal Python Web |
| Categories | Method Counts Object Oriented |
| Cost | Query |
| Suites | Chidamber & Kemerer |
Number of local (not inherited) methods.
Counts only methods actually written in the source — it combines both instance and static methods, across all access levels, but does not include compiler-generated implicit special members or anything inherited from a base class.
For example:
class BoatCar: private Car, public Boat, protected DualPurpose {
public:
// Public Instance Function
BoatCar() : Car(4), Boat(), mInWater(false), mColor("Blue") {}
virtual int passengers() const { return 4; }
static int numRegistered() { return sRegistered; }
bool mInWater; // Public Instance Variable
protected:
void toggleInWater(bool inWater) { mInWater = inWater; }
char * mColor; // Protected Instance Variable
friend void init() {}
static int sRegistered;
static double calcSpeed(double distance, double time) {
return distance/time;
}
private:
int mMaxPassengers;
void travel() {}
};
BoatCar explicitly writes 6 methods total: the constructor, passengers(), toggleInWater(bool), and travel() (instance), plus numRegistered() and calcSpeed(...) (static). So CountDeclMethod = 6. That splits cleanly by access level: 3 public (BoatCar(), passengers(), numRegistered()) + 2 protected (toggleInWater(bool), calcSpeed(...)) + 1 private (travel()) = 6, so CountDeclMethod = CountDeclMethodPublic + CountDeclMethodProtected + CountDeclMethodPrivate for this class.
See All Methods to also count methods inherited from base classes. For just the instance or class subset, see Instance Methods (which also counts the compiler-generated implicit special members) in contrast to Class Methods (the static ones). Other languages have access levels C++ doesn't: see Default Methods for Java's package-private methods, and Internal Methods/Protected Internal Methods for C#'s additional access levels.
Also known as Chidamber & Kemerer - Weighted Methods per Class (WMC).
- Basic: Project, Module, Class, Struct
- C#: Project, Class, Struct
- C++: Project, Class, Struct, Union
- Java: Project, File, Class, Interface
- Pascal: Project, Class, Interface
- Python: Project, Class
- Web: Project, PHP Class, PHP Interface