Refactoring Catalog — Code Refactoring Catalog
A reference of code smell-to-refactoring mappings, SOLID violation identification, and complexity metrics used by the architecture-reviewer and performance-analyst agents during code structure analysis.
Target Agents
architecture-reviewer — Applied when suggesting refactoring based on design patterns and SOLID principles
performance-analyst — Applied when suggesting refactoring related to complexity analysis and performance
Code Smell to Refactoring Mapping
Size-Related Smells
| Code Smell |
Symptoms |
Refactoring Technique |
| Long Method |
20+ lines |
Extract Method, Replace Temp with Query |
| Large Class |
300+ lines or 10+ fields |
Extract Class, Extract Subclass |
| Long Parameter List |
4+ parameters |
Introduce Parameter Object, Builder Pattern |
| Data Clumps |
Same field groups repeated |
Extract Class |
| Primitive Obsession |
Domain concepts as primitives |
Value Object, Enum |
Structure-Related Smells
| Code Smell |
Symptoms |
Refactoring Technique |
| Feature Envy |
Excessive use of another class's data |
Move Method |
| Data Class |
Class with only getters/setters |
Move behavior into class |
| Shotgun Surgery |
One change affects multiple classes |
Move Method/Field, Inline Class |
| Divergent Change |
One class changes for multiple reasons |
Extract Class (SRP) |
| Duplicated Code |
Identical/similar code repeated |
Extract Method, Template Method |
| Middle Man |
Class that only delegates |
Remove Middle Man, Inline Class |
| Inappropriate Intimacy |
Excessive coupling between classes |
Move Method/Field, Extract Class |
| Switch/If Chain |
Long conditional branching |
Replace Conditional with Polymorphism, Strategy |
| Refused Bequest |
Inherited but unused methods |
Replace Inheritance with Delegation |
| Comments |
Complex logic explained by comments |
Extract Method (self-documenting code) |
SOLID Principle Violation Identification
S — Single Responsibility Principle
| Violation Signal |
Identification Criteria |
Refactoring |
| Class name contains "And", "Manager" |
Implies multiple responsibilities |
Extract Class |
| 2+ reasons to change |
"If X changes this class changes, and if Y changes this class also changes" |
Separate classes by responsibility |
| Highly diverse imports |
Imports DB, HTTP, UI, logging all together |
Layer separation |
O — Open/Closed Principle
| Violation Signal |
Identification Criteria |
Refactoring |
| Switch/if modified when adding new types |
Existing code modification required |
Strategy Pattern, Polymorphism |
| Hardcoded branching |
Code added for each new condition |
Plugin/Registry pattern |
L — Liskov Substitution Principle
| Violation Signal |
Identification Criteria |
Refactoring |
| Override throws exception in child class |
NotImplementedError, UnsupportedOperationException |
Interface segregation, Inheritance to Composition |
| Type checking then casting |
instanceof / typeof branching |
Redesign with polymorphism |
I — Interface Segregation Principle
| Violation Signal |
Identification Criteria |
Refactoring |
| Empty interface implementations |
pass, {}, noop |
Interface segregation |
| "Fat" interface |
10+ methods |
Split into Role Interfaces |
D — Dependency Inversion Principle
| Violation Signal |
Identification Criteria |
Refactoring |
| Direct concrete class instantiation |
Hardcoded new ConcreteService() |
Dependency Injection |
| Upper module imports lower module |
Business logic directly uses DB library |
Interface/Port abstraction |
Complexity Measurement Criteria
Cyclomatic Complexity
Branch points (if/else/switch/for/while/catch) + 1
| Score |
Complexity |
Action |
| 1-5 |
Low |
Appropriate |
| 6-10 |
Medium |
Review with care |
| 11-20 |
High |
Refactoring recommended |
| 21+ |
Very high |
Refactoring required |
Cognitive Complexity
Difficulty of human code comprehension. Weight increases with deeper nesting.
| Element |
Base Increment |
Nesting Bonus |
| if/else/switch |
+1 |
+nesting level |
| for/while/do |
+1 |
+nesting level |
| catch |
+1 |
+nesting level |
| break/continue to label |
+1 |
- |
| Logical operator chain (&&, |
|
) |
| Recursive call |
+1 |
- |
Recommended Thresholds
| Metric |
Method/Function |
Class/File |
| Lines of code |
Under 20 |
Under 300 |
| Cyclomatic complexity |
10 or less |
- |
| Cognitive complexity |
15 or less |
- |
| Parameter count |
4 or less |
- |
| Nesting depth |
3 levels or less |
- |
| Dependency count |
- |
10 or less |
Design Pattern Application Guide
Smell to Pattern Mapping
| Problem Situation |
Applicable Pattern |
Effect |
| Behavioral branching via conditionals |
Strategy |
OCP compliance, easy to add new behaviors |
| Complex object creation logic |
Factory Method/Builder |
Encapsulate creation logic |
| Same algorithm skeleton, different details |
Template Method |
Remove duplication, isolate change points |
| Behavior changes based on state |
State |
Remove conditionals, clarify state transitions |
| Event propagation to multiple objects |
Observer |
Loose coupling |
| Integrating incompatible interfaces |
Adapter |
Integration without modifying existing code |
| Simplifying complex subsystems |
Facade |
Interface simplification |
| Dynamically adding features to objects |
Decorator |
Feature extension without inheritance |
Refactoring Priority Decision
Impact-Difficulty Matrix
|
Low Difficulty |
High Difficulty |
| High Impact |
Do immediately |
Plan then execute |
| Low Impact |
When time allows |
Defer (low cost-benefit) |
Refactoring Suggestion Format
[Severity] Code Smell: [Smell Name]
Location: [File:Line]
Current State: [Problem description]
Refactoring: [Technique name]
Expected Effect: [How it improves]
Estimated Difficulty: [Low/Medium/High]
1---2name: refactoring-catalog3description: Code refactoring catalog. An extension skill for architecture-reviewer/performance-analyst that provides Martin Fowler-based refactoring patterns, code smell detection-to-refactoring mapping, SOLID principle violation identification, and complexity measurement criteria. Use when reviewing code structure improvement involving 'refactoring', 'code smells', 'SOLID violations', 'complexity', 'design patterns', 'code quality', etc. Note: direct code modification and security analysis are outside the scope of this skill.4---56# Refactoring Catalog — Code Refactoring Catalog78A reference of code smell-to-refactoring mappings, SOLID violation identification, and complexity metrics used by the architecture-reviewer and performance-analyst agents during code structure analysis.910## Target Agents1112- `architecture-reviewer` — Applied when suggesting refactoring based on design patterns and SOLID principles13- `performance-analyst` — Applied when suggesting refactoring related to complexity analysis and performance1415## Code Smell to Refactoring Mapping1617### Size-Related Smells1819| Code Smell | Symptoms | Refactoring Technique |20|-----------|----------|----------------------|21| **Long Method** | 20+ lines | Extract Method, Replace Temp with Query |22| **Large Class** | 300+ lines or 10+ fields | Extract Class, Extract Subclass |23| **Long Parameter List** | 4+ parameters | Introduce Parameter Object, Builder Pattern |24| **Data Clumps** | Same field groups repeated | Extract Class |25| **Primitive Obsession** | Domain concepts as primitives | Value Object, Enum |2627### Structure-Related Smells2829| Code Smell | Symptoms | Refactoring Technique |30|-----------|----------|----------------------|31| **Feature Envy** | Excessive use of another class's data | Move Method |32| **Data Class** | Class with only getters/setters | Move behavior into class |33| **Shotgun Surgery** | One change affects multiple classes | Move Method/Field, Inline Class |34| **Divergent Change** | One class changes for multiple reasons | Extract Class (SRP) |35| **Duplicated Code** | Identical/similar code repeated | Extract Method, Template Method |36| **Middle Man** | Class that only delegates | Remove Middle Man, Inline Class |37| **Inappropriate Intimacy** | Excessive coupling between classes | Move Method/Field, Extract Class |38| **Switch/If Chain** | Long conditional branching | Replace Conditional with Polymorphism, Strategy |39| **Refused Bequest** | Inherited but unused methods | Replace Inheritance with Delegation |40| **Comments** | Complex logic explained by comments | Extract Method (self-documenting code) |4142## SOLID Principle Violation Identification4344### S — Single Responsibility Principle45| Violation Signal | Identification Criteria | Refactoring |46|-----------------|------------------------|-------------|47| Class name contains "And", "Manager" | Implies multiple responsibilities | Extract Class |48| 2+ reasons to change | "If X changes this class changes, and if Y changes this class also changes" | Separate classes by responsibility |49| Highly diverse imports | Imports DB, HTTP, UI, logging all together | Layer separation |5051### O — Open/Closed Principle52| Violation Signal | Identification Criteria | Refactoring |53|-----------------|------------------------|-------------|54| Switch/if modified when adding new types | Existing code modification required | Strategy Pattern, Polymorphism |55| Hardcoded branching | Code added for each new condition | Plugin/Registry pattern |5657### L — Liskov Substitution Principle58| Violation Signal | Identification Criteria | Refactoring |59|-----------------|------------------------|-------------|60| Override throws exception in child class | `NotImplementedError`, `UnsupportedOperationException` | Interface segregation, Inheritance to Composition |61| Type checking then casting | `instanceof` / `typeof` branching | Redesign with polymorphism |6263### I — Interface Segregation Principle64| Violation Signal | Identification Criteria | Refactoring |65|-----------------|------------------------|-------------|66| Empty interface implementations | `pass`, `{}`, `noop` | Interface segregation |67| "Fat" interface | 10+ methods | Split into Role Interfaces |6869### D — Dependency Inversion Principle70| Violation Signal | Identification Criteria | Refactoring |71|-----------------|------------------------|-------------|72| Direct concrete class instantiation | Hardcoded `new ConcreteService()` | Dependency Injection |73| Upper module imports lower module | Business logic directly uses DB library | Interface/Port abstraction |7475## Complexity Measurement Criteria7677### Cyclomatic Complexity78Branch points (if/else/switch/for/while/catch) + 17980| Score | Complexity | Action |81|-------|-----------|--------|82| 1-5 | Low | Appropriate |83| 6-10 | Medium | Review with care |84| 11-20 | High | Refactoring recommended |85| 21+ | Very high | Refactoring required |8687### Cognitive Complexity88Difficulty of human code comprehension. Weight increases with deeper nesting.8990| Element | Base Increment | Nesting Bonus |91|---------|---------------|---------------|92| if/else/switch | +1 | +nesting level |93| for/while/do | +1 | +nesting level |94| catch | +1 | +nesting level |95| break/continue to label | +1 | - |96| Logical operator chain (&&, ||) | +1 | - |97| Recursive call | +1 | - |9899### Recommended Thresholds100| Metric | Method/Function | Class/File |101|--------|----------------|-----------|102| Lines of code | Under 20 | Under 300 |103| Cyclomatic complexity | 10 or less | - |104| Cognitive complexity | 15 or less | - |105| Parameter count | 4 or less | - |106| Nesting depth | 3 levels or less | - |107| Dependency count | - | 10 or less |108109## Design Pattern Application Guide110111### Smell to Pattern Mapping112113| Problem Situation | Applicable Pattern | Effect |114|------------------|-------------------|--------|115| Behavioral branching via conditionals | **Strategy** | OCP compliance, easy to add new behaviors |116| Complex object creation logic | **Factory Method/Builder** | Encapsulate creation logic |117| Same algorithm skeleton, different details | **Template Method** | Remove duplication, isolate change points |118| Behavior changes based on state | **State** | Remove conditionals, clarify state transitions |119| Event propagation to multiple objects | **Observer** | Loose coupling |120| Integrating incompatible interfaces | **Adapter** | Integration without modifying existing code |121| Simplifying complex subsystems | **Facade** | Interface simplification |122| Dynamically adding features to objects | **Decorator** | Feature extension without inheritance |123124## Refactoring Priority Decision125126### Impact-Difficulty Matrix127128| | Low Difficulty | High Difficulty |129|--|---------------|----------------|130| **High Impact** | Do immediately | Plan then execute |131| **Low Impact** | When time allows | Defer (low cost-benefit) |132133### Refactoring Suggestion Format134```135[Severity] Code Smell: [Smell Name]136Location: [File:Line]137Current State: [Problem description]138Refactoring: [Technique name]139Expected Effect: [How it improves]140Estimated Difficulty: [Low/Medium/High]141```