scitools.com

← Metric catalog

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

Protected Methods

API ID: CountDeclMethodProtected
Languages: Basic, C#, C++, Java, Pascal, Web
Targets: Architectures, Classes, Files, Modules, Project

Number of local protected methods.

Counts protected methods regardless of whether they're instance or static methods.

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's protected: section declares two methods — toggleInWater(bool) (an instance method) and calcSpeed(double, double) (a static method) — so CountDeclMethodProtected = 2.

See Methods for the total, and Public Methods / Private Methods for the other two access levels. Some languages have additional access levels: see Default Methods for Java's package-private methods, and Internal Methods/Protected Internal Methods for C#'s additional access levels, and Strict Protected Methods for Object Pascal's narrower variant.


Targets By Language: Configuration: