Instance 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.
Instance Methods
| Also Known As | Number of Instance Methods (NIM) |
| API ID | CountDeclInstanceMethod |
| Targets | Architectures Classes Files Project |
| Languages | Basic C# C++ Java Pascal Python Web |
| Categories | Method Counts Object Oriented |
| Cost | Query |
| Suites | Lorenz & Kidd |
Number of instance methods.
Methods defined in a class that are only accessable through an object of that 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 4 instance methods: the BoatCar() constructor, passengers(), toggleInWater(bool), and travel(). Understand also counts the compiler-generated special member functions that C++ synthesizes automatically whenever they aren't explicitly declared: the copy constructor BoatCar(const BoatCar&), move constructor BoatCar(BoatCar&&), destructor ~BoatCar(), copy assignment operator=(const BoatCar&), and move assignment operator=(BoatCar&&). That's 4 explicit plus 5 implicit, for CountDeclInstanceMethod = 9.
See Class Methods for static methods, and Methods for the count of only what's actually written in the source.
Also known as Lorenz & Kidd - Number of Instance Methods (NIM).
- Basic: Project, 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