scitools.com

← Metric catalog

Instance Variables 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 Variables

Also Known AsNumber of Instance Variables (NIV)
API IDCountDeclInstanceVariable
TargetsArchitectures Classes Files Project
LanguagesBasic C# C++ Java Pascal Python Web
CategoriesObject Oriented Variable Counts
CostQuery
SuitesLorenz & Kidd

Number of instance variables.

Variables defined in a class that are only accessible 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 declares three instance variables across all access levels — mInWater (public), mColor (protected), and mMaxPassengers (private) — so CountDeclInstanceVariable = 3.

See Public Instance Variables, Protected Instance Variables, and Private Instance Variables for the breakdown by access level, and Class Variables for the static counterpart. C# also has additional access levels: see Internal Instance Variables and Protected Internal Instance Variables.

Also known as Lorenz & Kidd - Number of Instance Variables (NIV).


Targets By Language: