BloatersCritical

God Class: What It Costs and How to Fix It

A class that knows too much and does too much, concentrating responsibilities that should be distributed.

Annual Cost$8k - $62k
Severity
5/5
CategoryBloaters
Detection4 tools

What It Is

A God Class (also called Large Class or Blob) is a class that has accumulated so many fields, methods, and responsibilities that it becomes the gravitational centre of the codebase. Everything depends on it, everyone modifies it, and nobody fully understands it. God Classes typically start as reasonable domain objects that grow incrementally over months or years. Each addition seems small, but the cumulative effect creates a class that violates the Single Responsibility Principle so thoroughly that it becomes a bottleneck for the entire team.

Threshold: Classes above 500 lines deserve scrutiny. Classes above 1,000 lines are almost certainly god classes. The most reliable indicator is the number of reasons to change: if a class changes for 3+ distinct business reasons, it is a god class.

Why It Costs Money

1

Merge conflicts become routine. When a 2,000-line class is modified by 3-4 developers simultaneously, merge conflicts occur on nearly every sprint. Teams with god classes report spending 2-5 hours per developer per week resolving merge conflicts in these files alone.

2

Onboarding delay increases sharply. New developers need 2-3 additional weeks to become productive in modules dominated by god classes, because they must understand the entire class before they can safely change any part of it.

3

Bug clustering is severe. Research shows that 60% of production bugs originate in the top 5% largest classes. God Classes are almost always in that top 5%, making them the single largest source of production incidents.

Specific Cost Mechanisms

  • Merge conflict resolution: 2-5 hours per developer per week when actively developing features that touch the god class
  • Onboarding delay: 2-3 weeks of additional ramp time per new hire, at fully-loaded salary cost
  • Bug investigation: god class bugs take 2-3x longer to diagnose because the class has so many interacting state variables

Estimated Annual Cost

Cost per instance by team size and codebase size. Based on $120,000 average developer salary. See full methodology.

Team SizeSmall (<50k LOC)Medium (50k-200k)Large (200k+)
3 devs$8,000$18,000$36,000
5 devs$14,000$30,000$50,000
10 devs$22,000$42,000$62,000
20 devs$30,000$55,000$62,000

How to Detect It

Specific rules and thresholds for automated detection. See full tool comparison.

SonarQube
squid:S1200 / squid:S2972

Class coupling > 20, class lines > 750

CodeClimate
file-lines / method-count

File lines > 250, method count > 20

ESLint
max-lines / max-classes-per-file

Set file max to 300 lines for JS/TS

PMD
GodClass / ExcessiveClassLength

Detects classes with high WMC (Weighted Methods per Class)

Refactoring Patterns

Proven techniques to eliminate this smell. See all refactoring patterns.

Extract Class

Groups of fields and methods that form a coherent subset of the class responsibilities

Effort: 4-16 hours depending on coupling
Impact: 30-50% reduction in merge conflicts per extraction

Extract Subclass

Some instances use only a subset of the class features

Effort: 2-8 hours
Impact: Reduces class size and enables targeted testing

Replace Data Value with Object

Primitive fields that carry behaviour elsewhere in the god class

Effort: 1-4 hours per data cluster
Impact: 10-20% reduction per extraction, cumulative

Related Smells