refactor-extract-and-isolate
[Code Quality] Extracts methods, classes, or modules to reduce complexity and improve isolation. Use when functions are too long, classes have too many responsibilities, or concerns are mixed.
When & Why to Use This Skill
This Claude skill automates the code refactoring process by extracting methods, classes, and modules to reduce technical debt and improve system isolation. It helps developers transform complex, 'spaghetti' code into a clean, modular architecture by identifying bloated functions and over-responsible classes, ensuring long-term maintainability and better adherence to the Single Responsibility Principle.
Use Cases
- Simplifying Bloated Functions: Automatically break down long methods (20+ lines) or deeply nested logic into smaller, descriptive, and reusable functions to enhance readability.
- Decomposing 'God Objects': Identify classes with too many responsibilities and extract them into focused, cohesive units to improve modularity and reduce side effects.
- Decoupling for Testability: Extract protocols or interfaces from concrete implementations to facilitate dependency inversion, making it easier to mock components during unit testing.
- Eliminating Code Duplication: Detect repeated logic patterns across a codebase and consolidate them into a single extracted module or utility class to streamline updates.
| name | refactor-extract-and-isolate |
|---|---|
| description | "[Code Quality] Extracts methods, classes, or modules to reduce complexity and improve isolation. Use when functions are too long, classes have too many responsibilities, or concerns are mixed." |
Refactor: Extract and Isolate
Break down complex code into focused, reusable units.
Extract Method
When to Extract
- Function > 20 lines
- Code block has a distinct purpose
- Same logic repeated
- Deep nesting (> 3 levels)
Extract Class
When to Extract
- Class > 300 lines
- Multiple distinct responsibilities
- Group of related methods/properties
- Feature envy
Extract Protocol/Interface
When to Extract
- Multiple implementations possible
- Testing requires mocking
- Dependency inversion needed
Checklist
- Identify extraction boundary
- Choose good name for new unit
- Move code to new location
- Update references
- Add tests for new unit
- Verify original tests pass