God Objects: When One Class Does Everything
You'll learn to recognize when a single object has become bloated with too many responsibilities and why that's a design problem.
What Is a God Object?
A God Object (or "God Class") is an antipattern where one class or object tries to do everything. It handles multiple unrelated responsibilities—data management, business logic, UI updates, API calls, validation, logging, and more—all crammed into one massive structure.
Think of it like a Swiss Army knife that's been taken too far: instead of a few useful tools, it has 200 attachments. Sure, it can do everything, but it's unwieldy, hard to maintain, and impossible to understand at a glance.
Why It's Problematic
Hard to understand: When a class has 50 methods spanning different concerns, no one knows what it really does.
Hard to test: Testing requires mocking everything from databases to DOM elements because it touches everything.
Hard to change: Modifying one feature risks breaking unrelated features buried in the same class.
Violates Single Responsibility Principle: Each class should have one clear purpose. God Objects have many.
Example Symptom
class UserManager {
validateEmail() { /*...*/ }
hashPassword() { /*...*/ }
saveToDatabase() { /*...*/ }
sendWelcomeEmail() { /*...*/ }
renderProfilePage() { /*...*/ }
logActivity() { /*...*/ }
calculateRewards() { /*...*/ }
// ... 40 more methods
}
This class handles validation, persistence, email, rendering, logging, and business logic. That's at least six different responsibilities.
The Solution
Break it apart! Extract cohesive responsibilities into separate classes or modules: EmailValidator, PasswordHasher, UserRepository, EmailService, ProfileRenderer, Logger, RewardsCalculator. Each does one thing well, and UserManager coordinates them.
Key Takeaway: When a class grows to handle multiple unrelated concerns, it becomes a God Object—hard to maintain, test, and understand. Break large objects into focused, single-responsibility components.