Large Class — Code Smells Catalog Skip to content

Large Class

Also known as: Blob, Brain Class, Complex Class, God Class, God Object, Schizophrenic Class, Ice Berg Class

Bloaters Measured Smells AntipatternArchitecture SmellCode SmellDesign Smell Within Class

The God Class. Too many methods, too many fields, too many reasons to exist. Reading it takes a morning, testing it takes a sprint, and changing it is a gamble that affects everything it touches.

2 min read 1 source

Overview

When one combines the smell of Long Method and Long Parameter List, but on a higher abstraction level, then he would get the Large Class code smell. Many long-form methods and an abundant number of parameters that can be passed to a class cause Large Class problems. The point is that the class has too many responsibilities and is doing too much.

Causation

This problem occurs because, under time constraints, it is much easier to place a new code in an existing class than to create a whole new class for the feature.

Problems

👁
Hard to Read and Understand

Large components are hard to comprehend, which amplifies if the element is not purely functional and stateless.

Hard to Change

It is tough to assess where the change has to be made, and even after it is done, the developer has to verify whether that was the only one in the class that had to be changed to implement his new desired functionality. There is also the risk of breaking the functionalities of all the other responsibilities that the class has and breaking by making unexpected side effects.

🧪
Hard to Test

The larger the class, the more potential scenarios (all the methods and state variations) have to be covered via tests.

Refactoring

  • Extract Class
  • Extract Subclass
  • Extract Interface
  • Extract Domain Object
  • Replace Data Value with object

Sources

Browse All 56 Smells