Large Class Smell
You'll learn to spot classes that do too much and understand why they break the Single Responsibility Principle.
What is Large Class Smell?
A Large Class is a code smell where a single class has grown too large—either with too many fields, too many methods, or both—because it's trying to handle multiple responsibilities at once. This directly violates the Single Responsibility Principle (SRP), which states that a class should have only one reason to change.
Think of it like a Swiss Army knife that's gotten out of control. Instead of just a knife, scissors, and screwdriver, it now includes a can opener, flashlight, radio, GPS, coffee maker, and tent. It's become unwieldy and hard to use because it's trying to be everything at once.
Recognizing Large Class Smell
Watch for these warning signs:
- Too many fields: The class tracks dozens of instance variables
- Too many methods: Scrolling through hundreds of lines to find what you need
- Multiple concerns: The class handles user input and database logic and business rules and formatting
- Difficult naming: You can't give the class a clear, specific name without using "and" or "Manager" or "Helper"
Why It Matters
Large classes become maintenance nightmares. When you need to modify one responsibility, you risk breaking others. Testing becomes harder because you can't isolate behavior. Understanding what the class actually does requires reading through vast amounts of unrelated code.
The Solution Preview
The fix involves extracting classes—pulling related fields and methods into new, focused classes that each handle one responsibility. We'll cover specific extraction techniques in upcoming lessons.
Key Takeaway: A Large Class tries to do too much, violating SRP and making code harder to understand, test, and maintain—recognize it by counting responsibilities, not just lines of code.