Public 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.
Public Methods
| Also Known As | Number of Public Methods (PM NPM) Public Instance Methods (PIM) |
| API ID | CountDeclMethodPublic |
| Targets | Architectures Classes Files Modules Project |
| Languages | Basic C# C++ Java Pascal Web |
| Categories | Method Counts Object Oriented |
| Cost | Query |
| Suites | Lorenz & Kidd |
Number of local (not inherited) public 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 public: section declares three methods — the BoatCar() constructor, passengers() const, and the static numRegistered() — so CountDeclMethodPublic = 3.
See Methods for the total, and Protected 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 Published Methods for Object Pascal's public-with-RTTI level.
Also known as Lorenz & Kidd - Public Instance Methods (PIM); Number of Public Methods (PM, NPM).
- Basic: Project, Module, Class, Struct
- C#: Project, Class, Struct
- C++: Project, Class, Struct, Union
- Java: Project, File, Class, Interface
- Pascal: Project, Class, Interface
- Web: Project, PHP Class, PHP Interface