Afferent Coupling at Type Level for C++
Coupling is metric which can be computed for structural units at different levels (e.g. classes, namespaces, modules). It measures how many other entities an entity depends on; and how many dependants it has.
The Afferent Coupling for a particular type is the number of types that depends directly on it.
High afferent coupling indicates that the concerned types have many responsibilities, while a zero value could indicate unused code.
Counts:
- Member user-defined types
- Member function parameter user-defined types
- Member function local variable user-defined types
- User-defined type inheritance
Remaining questions @mcserep :
- Which user-defined types count? Only those defined in the analyzed code? How did I know whose are defined in the user space?
- What about
std::vector<A>orstd::unique_ptr<A>? Are these different thanA? - What is about
MyTemplate<A>andMyTemplate<B>? Are these different? - Probably when we count the classes, the
std::decay_t<type>is matter (A, A* and A[4]* is not different). Is that right?
Which user-defined types count? Only those defined in the analyzed code? How did I know whose are defined in the user space?
Types which are defined in files under the project root. (Given with the -i flag for the parser.) Special attention could be required for template types.
What about std::vector<A> or std::unique_ptr<A>? Are these different than A?
If type B uses A, std::vector<A> and std::unique_ptr<A>, then it increases the afferent coupling with 1.
If type B uses std::vector<std::map<A, C>>, then B depends on A and C as well.
What is about
MyTemplate<A>andMyTemplate<B>? Are these different?
This means all 3 types are used.
Probably when we count the classes, the
std::decay_t<type>is matter (A, A* and A[4]* is not different). Is that right?
Type A should be counted here.