Also called God object, Blob class, Large class
In depth What is refactoring: the techniques behind splitting a class, and how to do it safely.
How a god class is detected
No single metric defines a god class. Detectors combine signals, because size alone flags harmless classes and misses tangled ones.
- Size. Many methods and fields, or a high weighted method count (the sum of the complexity of its methods).
- Many responsibilities. The class does several jobs: parsing, validation, persistence and formatting in one place.
- Low cohesion. Its methods split into groups that share no fields. LCOM4 (lack of cohesion of methods, version 4) counts those groups: 1 means the class hangs together, 2 or more means it is several classes in one file.
- High coupling. It uses the data of many other classes directly, which shows up as many outgoing dependencies.
The best known combination is the god class detection strategy from Michele Lanza and Radu Marinescu's book Object-Oriented Metrics in Practice (2006). It flags a class that is complex, accesses a lot of foreign data and has low tight class cohesion. PMD ships a GodClass rule built on it, and SonarQube and Checkstyle cover the same ground with class size and coupling rules. Thresholds differ between tools, so treat any single number as a prompt to look, not a verdict.
Why a god class hurts
A god class concentrates change. Every feature touching that area edits the same file, so it collects merge conflicts, review fatigue and regressions. It is hard to test, because each test has to build the whole object. And because so much depends on it, a mistake in it has a wide blast radius.
These classes rarely start out that way. Someone adds one more method to the class that already has the data, and each addition is reasonable. Watch the files that are large and also change often: that overlap is where a god class costs real time, and it is where technical debt compounds fastest.
How to split a god class
The standard move is Extract Class, from Fowler's refactoring catalogue. A mechanical way to find the seams:
- List the class's fields and which methods read or write each one.
- Group methods that share fields. Each connected group is a candidate class. These are the LCOM4 components.
- Move one group, with the fields only it uses, into a new class.
- Have the original delegate to the new class, or call the new class directly and delete the delegation.
- Run the tests after each move, not at the end.
Methods that touch fields from several groups are the hard part. They usually belong to whichever group they use most, or need to be split themselves. If no test reaches the code, write a characterization test first so you can tell a behaviour change from a move. The same family of smells, including long methods and feature envy, is covered in what is a code smell.
How repowise finds and splits god classes
repowise raises a god_class finding as part of its code health analysis, and the Extract Class refactoring plan answers it. The plan names the cohesive groups, meaning the methods and fields, that an incohesive or god class splits into. It is built from the class model, the dependency graph and git history, during repowise init and repowise update, with no LLM key and no network call.
Each plan carries its evidence, such as the LCOM4 measurement, a confidence level (low, medium or high), an effort bucket from S to XL and a blast radius that lists callers and co-change partners. It also lists the tests closest to the change, so you know which to run. A group the code gives no name for is left unnamed and held back for design instead of being given an invented one, and a plan never edits your files.
repowise health --refactoring-targets
repowise health --plan <plan-id>The second command prints one plan as the prompt a coding agent applies. See refactoring plans and the guide to what refactoring is. For how complexity metrics feed the same health score, see cyclomatic complexity and cognitive complexity.