Glossary · Code health

What is a god class?

A god class is a class that does too much: it holds many fields and methods, mixes several unrelated responsibilities and reaches into the data of other classes. Fowler and Beck's Refactoring calls the same smell Large Class. Because so much logic lives there, most changes to the system end up touching it.

Last reviewed: November 2026

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:

  1. List the class's fields and which methods read or write each one.
  2. Group methods that share fields. Each connected group is a candidate class. These are the LCOM4 components.
  3. Move one group, with the fields only it uses, into a new class.
  4. Have the original delegate to the new class, or call the new class directly and delete the delegation.
  5. 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.

FREQUENTLY ASKED

God class: questions

What is the difference between a god class and a large class?

Size alone makes a large class. A god class is large and also takes on several responsibilities and depends on other classes' data. A big class with one clear job, such as a parser, is large but not a god class.

How many lines make a class a god class?

There is no standard line count. Line count is a weak signal on its own, so detectors combine it with cohesion and coupling measures. A 600-line class whose methods all share the same fields is healthier than a 300-line class made of three unrelated halves.

Why is a god class bad?

Everything changes it, so it collects merge conflicts and regressions. Its tests are hard to write because each one needs the whole class set up, and nobody can understand it in one sitting. It also tends to sit at the centre of the dependency graph, so a change there has a wide blast radius.

How do you refactor a god class?

Group its methods by the fields they share, move each group into its own class with Extract Class, and keep the original as a thin coordinator or delete it. Add a characterization test first if no test reaches the code, and move one group at a time.

See it on your own repository.

Index a repository free and read the result for your own code and history. Or explore a live repo first.