Protected 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.
Protected Instance Variables
API ID: CountDeclInstanceVariableProtectedLanguages: C#, C++, Web
Targets: Architectures, Classes, Project
Number of protected instance variables.
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 one instance variable in its protected: section, mColor, so CountDeclInstanceVariableProtected = 1.
See Instance Variables for the total across all access levels, and Private Instance Variables / Public Instance Variables for the other two. C# also has additional access levels: see Internal Instance Variables/Protected Internal Instance Variables.
- C#: Project, Class, Struct
- C++: Project, Class, Struct, Union
- Web: Project, PHP Class, PHP Interface
- For projects and architectures, this metric must also be enabled from "Project Configuration/Metrics/Projects and Architectures" with the "Show aggregated class metrics" option. Enabling this option can be time consuming.
- This metric can be disabled from "Project Configuration/Metrics/Object Orientated" with the "Show method and variable count metrics" option.