God Class
Class Strategy | Multi-metric
A class that has accumulated too many responsibilities: it is complex (high WMC), incoherent (low TCC), and data-hungry — reaching into too many other classes to read their data (high ATFD).
Detection Rule
WMC > 47 AND TCC < 0.33 AND ATFD > 5
| Metric | Threshold | Meaning when exceeded |
|---|---|---|
| WMC | > 47 | Class has a large total cyclomatic complexity across all methods |
| TCC | < 0.33 | Less than a third of method pairs share a common field — low cohesion |
| ATFD | > 5 | More than 5 distinct foreign-class field accesses — class reaches outside itself |
What is ATFD?
Access to Foreign Data (ATFD) counts member expressions where the base object is an external identifier (not this or super). Chained access a.b.c counts as one access for a.
// These count toward ATFD:
order.status // foreign field: order
user.profile.name // foreign field: user (chained, counts once)
config.timeout // foreign field: config
// These do NOT count:
this.items.length // this-based
super.value // super-based
TypeScript Example
class ApplicationManager {
// 15 methods (WMC=52) — exceeds 47 ✓
// TCC=0.12 — methods don't share fields ✓
// ATFD=9 — reads from user, session, config, db, ... ✓
processOrder(o: Order) {
if (o.status === "pending") {
this.db.save(o);
this.emailSvc.notify(o.user.email);
this.analytics.track(o.id);
}
}
// ... 14 more methods of similar reach
}
// 🚨 God Class detected
Remediation
- Apply the Extract Class refactoring to split responsibilities.
- Group methods that share fields into smaller, cohesive classes.
- Move methods that envy another class into that class (Feature Envy).
- Replace foreign-data access with a service or repository pattern.