All 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.
All Methods
API ID: CountDeclMethodAllAlso Known As: Number of Methods (NM), Response for a Class (RFC)
Languages: Basic, C#, C++, Java, Pascal, Python, Web
Targets: Classes
Number of methods, including inherited ones.
For example:
class Vehicle {
public:
Vehicle() {}
};
class Wheeled : public Vehicle {
public:
Wheeled(int wheels) : mWheels(wheels) {}
int wheels() { return mWheels; }
void setWheels(int wheels) { mWheels = wheels; }
private:
int mWheels;
};
class Car : public Wheeled {
public:
Car() : Wheeled(4) {}
Car(int wheels) : Wheeled(wheels) {}
};
class Boat : public Vehicle {
public:
Boat() {}
~Boat() {}
};
class DualPurpose {
public:
DualPurpose() {}
char* purpose1() { return nullptr; }
char* purpose2() { return nullptr; }
};
class BoatCar: private Car, public Boat, protected DualPurpose {
public:
BoatCar() : Car(4), Boat(), mInWater(false), mColor("Blue") {}
virtual int passengers() const { return 4; }
static int numRegistered() { return sRegistered; }
bool mInWater;
protected:
void toggleInWater(bool inWater) { mInWater = inWater; }
char * mColor;
friend void init() {}
static int sRegistered;
static double calcSpeed(double distance, double time) {
return distance/time;
}
private:
int mMaxPassengers;
void travel() {}
};
class TourBoatCar : public BoatCar {};
class WildLifeTourBoatCar: public TourBoatCar {};
BoatCar writes 6 methods of its own and multiply inherits from Car (which itself derives from Wheeled, which derives from Vehicle), Boat (which also derives from Vehicle), and DualPurpose. Counting the transitive union of all of those methods — and only counting Vehicle's single constructor once even though it's reachable through both the Car/Wheeled chain and the Boat chain — gives CountDeclMethodAll = 17 for BoatCar. TourBoatCar and WildLifeTourBoatCar add no methods of their own, so they inherit everything BoatCar has unchanged: both also show CountDeclMethodAll = 17.
See Methods to count only methods declared locally in the class itself.
Also known as Chidamber & Kemerer - Response for a Class (RFC); Lorenz & Kidd - Number of Methods (NM).
- Basic: Class, Struct
- C#: Class, Struct
- C++: Class, Struct, Union
- Java: Class, Interface
- Pascal: Class, Interface
- Python: Class
- Web: PHP Class, PHP Interface
- This metric can be disabled from "Project Configuration/Metrics/Object Orientated" with the "Show method and variable count metrics" option.