scitools.com

← Metric catalog

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

API ID: CountDeclInstanceMethod
Also Known As: Number of Instance Methods (NIM)
Languages: Basic, C#, C++, Java, Pascal, Python, Web
Targets: Architectures, Classes, Files, Project

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).


Targets By Language: Configuration: