Standard Analyses

SemmleCode Professional comes with a wide range of pre-packaged analyses, from architectural properties and metrics, to statement-level checks for likely bugs and violations of best practice.


Hub Types

This query shows coupling between classes and interfaces, grouped by package. Large boxes represent types with high afferent coupling (i.e., types on which many other types depend), small boxes are types with low afferent coupling. Red boxes represent types with high efferent coupling (i.e., types that depend on many other types), green boxes are types with low efferent coupling. In particular, hub types are represented by large, red boxes. Library types are not included in the analysis.

How to Interpret the Query Results

Running this query on the source code of the Roller blog software yields the following result, displayed as a tree map:

Every individual box represents a type (i.e., class or interface), with types within the same package grouped together. The size of a box represents the afferent coupling of the corresponding type, i.e. the number of types that depend on it, whereas its colour represents the efferent coupling of the type, i.e. the number of types it depends on. Hovering the mouse pointer over a type displays the values of afferent and efferent coupling.

Large boxes are types on which many other types depend: changing such a type is likely to affect large parts of the program. Red boxes are types which depend on many other types: such types are easily affected by changes in other parts of the program. Large, red types, in particular, are hub types that are both vulnerable to change and likely to influence others if changed. In Roller, WebsiteData is such a hub type, since there are 156 types depending on it, and it depends on 22 types itself. The type RollerException, on the other hand, is not so problematic: although it has high afferent coupling, its efferent coupling is very low, as seen by the green color of the box representing it.

How to Address the Query Results

You might consider refactoring hub types to decrease their number of dependencies.

Source Code
import default 
 
from RefType t
where t.fromSource()
select t.getPackage() as Package, 
       t as Type,
       t.getMetrics().getAfferentCoupling() as AfferentCoupling, 
       t.getMetrics().getEfferentSourceCoupling() as EfferentCoupling
order by AfferentCoupling desc
References