Back to Catalog
Code Smells
Bloaters
Large Class
Classes that have grown too large and handle too many responsibilities.
Intent & Description
'
🎯 Intent
Identify classes that have become too large and complex, violating Single Responsibility Principle and becoming difficult to maintain.
📋 Context
You have classes with hundreds of lines, many methods, and multiple responsibilities. Understanding the class requires significant effort, and changes risk breaking unrelated functionality.
💡 Solution
Break down large classes into smaller, focused classes. Extract related methods and fields into separate classes. Apply Extract Class and Single Responsibility Principle.'
Real-world Use Case
Use when classes exceed a few hundred lines, when they handle multiple concerns, or when they’re difficult to understand and modify.
Source
📌 TL;DR
Large classes violate SRP and are hard to maintain. Split them into focused, single-purpose classes. Apply Extract Class refactoring.
Advantages
- Focused, single-purpose classes
- Easier to understand and maintain
- Better adherence to SRP
Disadvantages
- Can increase number of classes
- May require careful coordination
Implementation Example
// Before: Large class
class User {
constructor(name, email, password) {
this.name = name;
this.email = email;
this.password = password;
this.orders = [];
this.addresses = [];
this.preferences = {};
this.notifications = [];
}
validateEmail() { /* ... */ }
validatePassword() { /* ... */ }
hashPassword() { /* ... */ }
addOrder(order) { /* ... */ }
getOrders() { /* ... */ }
addAddress(address) { /* ... */ }
getAddresses() { /* ... */ }
updatePreferences(prefs) { /* ... */ }
sendNotification(notification) { /* ... */ }
// ... many more methods
}