computeNodeDegreeMetrics function

void computeNodeDegreeMetrics(
  1. DirectedGraph<String> graph,
  2. @modified Model model
)

Compute node inDegree, outDegree, isOrphan, and instability. inDegree is the number of nodes that depend on this node. outDegree is the number of nodes this node depends on. Instability is a node metric by Robert C. Martin related to the Stable-Dependencies Principle: Depend in the direction of stability. Instability = outDegree / (inDegree + outDegree) In general, node instability should decrease in the direction of dependency. In other words, lower level nodes should be more stable and more reusable than higher level nodes.

Implementation

void computeNodeDegreeMetrics(
    DirectedGraph<String> graph, @modified Model model) {
  for (var v in graph.vertices) {
    model.nodes[v]!.inDegree = graph.inDegree(v);
    model.nodes[v]!.outDegree = graph.outDegree(v);
    if (model.nodes[v]!.inDegree! + model.nodes[v]!.outDegree! > 0) {
      model.nodes[v]!.instability = (model.nodes[v]!.outDegree! /
              (model.nodes[v]!.inDegree! + model.nodes[v]!.outDegree!))
          .toPrecision(precision) as double?;
    }
  }
}