scitools.com

← Metric catalog

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

Class Methods

API ID: CountDeclClassMethod
Also Known As: Number of Class Methods (NCM)
Languages: Basic, C#, C++, Java, Pascal, Web
Targets: Architectures, Classes, Files, Project

Number of class methods.

A "class method" is a static member function — one that belongs to the class as a whole rather than to any particular object, and so can be called without an instance.

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 declares two static methods, numRegistered() and calcSpeed(...), so CountDeclClassMethod = 2.

See Instance Methods for methods that require an object to call, and Methods for the combined total.

Also known as Lorenz & Kidd - Number of Class Methods (NCM).


Targets By Language: Configuration: