TCC — Tight Class Cohesion
Class Metric | AST-based | Range [0, 1]
Fraction of method pairs in a class that are directly connected — i.e., both access at least one common this field.
Formula
TCC = connected_pairs / total_pairs
total_pairs = N × (N − 1) / 2 (where N = number of non-static methods)
Returns 1.0 (vacuously cohesive) when there are fewer than 2 non-static methods.
Connection rule
Two methods are connected when their sets of this.field accesses share at least one field name. Only this.identifier patterns are counted (not chained like this.a.b).
Static methods are excluded entirely.
Arrow function bodies inside a method do contribute (they capture lexical this); regular nested function bodies do not.
TypeScript Example
class Counter {
private count = 0;
private step = 1;
increment() { this.count += this.step; } // uses: count, step
reset() { this.count = 0; } // uses: count
getStep() { return this.step; } // uses: step
}
// Pairs: (inc,reset)→count ✓ (inc,getStep)→step ✓ (reset,getStep)→∅ ✗
// TCC = 2/3 ≈ 0.67
Thresholds
TCC is not threshold-checked independently. It contributes to the God Class strategy (TCC < 0.33 is a required condition).
Related metrics
WMC · WOC · God Class strategy