CodeCompass icon indicating copy to clipboard operation
CodeCompass copied to clipboard

Afferent Coupling at Type Level for C++

Open mcserep opened this issue 2 years ago • 2 comments

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.

mcserep avatar Nov 08 '23 12:11 mcserep

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> or std::unique_ptr<A>? Are these different than A?
  • What is about MyTemplate<A> and MyTemplate<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?

schaumb avatar Nov 29 '23 14:11 schaumb

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> and MyTemplate<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.

mcserep avatar Dec 13 '23 13:12 mcserep