Friend 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.
Friend Methods
API ID: CountDeclMethodFriendAlso Known As: Number of Friend Methods (NFM), Number of Friends (NF)
Languages: C++
Targets: Classes
Number of local (not inherited) friend methods.
The number of friend functions plus the Methods of any friend classes.
For example:
class FriendDemo {
friend class CohesionClass;
friend void init();
};
class CohesionClass {
public:
void func1() {
for (int i = 0; i < mVar1; i++) {
mVar2 = nullptr;
}
mVar1 = 3;
}
void func2() {
mVar1 = 4;
}
static void addObj() {
sNumObjs ++;
}
protected:
void func3() {
mVar2 = "blue";
}
private:
void func4() {
}
int mVar1;
char * mVar2;
static int sNumObjs;
};
FriendDemo declares one friend function, init(), and one friend class, CohesionClass. CohesionClass itself has 5 local methods (func1, func2, func3, func4, addObj), i.e. CountDeclMethod = 5 for CohesionClass. So FriendDemo's CountDeclMethodFriend = 1 + 5 = 6 — the friend function plus all of the friend class's own methods, not just the ones that actually use FriendDemo.
See Methods for a class's own local method count, which is what gets added in for each friend class, and the Friend References interactive report to see how, if at all, a given friend actually uses that access.
Also known as Lorenz & Kidd - Number of Friends (NF); Number of Friend Methods (NFM).
- C++: Class, Struct, Union
- This metric can be disabled from "Project Configuration/Metrics/Object Orientated" with the "Show method and variable count metrics" option.