Skip to content
Skills Library
Programming · Learning & explanation

refactoring

/refactoring

Reference for 89 refactoring techniques and 22 code smells with mechanics and before/after examples. Use to detect smells, clean up technical debt, or choose a technique.

Licence
MIT
Last repository change
23.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
90
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 23.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Reference for 89 refactoring techniques and 22 code smells with mechanics and before/after examples. Use to detect smells, clean up technical debt, or choose a technique.

Original author description

Reference for 89 refactoring techniques and 22 code smells with mechanics and before/after examples. Use to detect smells, clean up technical debt, or choose a technique.

How it works

  1. Refactoring techniques (67)
  2. Code smells (22)
  3. Best practices
Original SKILL.md headings · 129 lines, 1,287 words
SKILL.md preview
---
name: refactoring
description: Reference for 89 refactoring techniques and 22 code smells with mechanics and before/after examples. Use to detect smells, clean up technical debt, or choose a technique.
allowed-tools: Read Grep Glob Bash
user-invocable: true
disable-model-invocation: true
---

# Refactoring

Reference for 89 refactoring techniques and code smells. Each entry has examples in PHP, Python, TypeScript, Java, C# and others, rationale, step-by-step mechanics, and before/after comparisons.

## Refactoring techniques (67)

### Composing methods
- **Extract Method**: Pull code fragments into named methods → [reference](references/extract-method.md)
- **Inline Method**: Substitute a method call with its body → [reference](references/inline-method.md)
- **Extract Variable**: Name complex expressions with explanatory variables → [reference](references/extract-variable.md)
- **Inline Temp**: Substitute a temporary variable with its expression → [reference](references/inline-temp.md)
- **Replace Temp with Query**: Swap temp variables for method calls → [reference](references/replace-temp-with-query.md)
- **Split Temporary Variable**: Assign separate variables for separate purposes → [reference](references/split-temporary-variable.md)
- **Remove Assignments to Parameters**: Use local variables instead of reassigning parameters → [reference](references/remove-assignments-to-parameters.md)
- **Replace Method with Method Object**: Convert a complex method into its own class → [reference](references/replace-method-with-method-object.md)
- **Substitute Algorithm**: Swap an algorithm for a clearer alternative → [reference](references/substitute-algorithm.md)

### Moving features between objects
- **Move Method**: Move a method to the class that depends on it most → [reference](references/move-method.md)
- **Move Field**: Move a field to the class that depends on it most → [reference](references/move-field.md)
- **Extract Class**: Divide a class that handles too much → [reference](references/extract-class.md)
- **Inline Class**: Consolidate a class that does too little → [reference](references/inline-class.md)
- **Hide Delegate**: Add methods that hide delegation chains → [reference](references/hide-delegate.md)
- **Remove Middle Man**: Let clients call the delegate directly → [reference](references/remove-middle-man.md)
- **Introduce Foreign Method**: Attach a missing method to a class you cannot modify → [reference](references/introduce-foreign-method.md)
- **Introduce Local Extension**: Build a wrapper or subclass for a library class → [reference](references/introduce-local-extension.md)

### Organizing data
- **Self Encapsulate Field**: Route field access through getters even within the class → [reference](references/self-encapsulate-field.md)
- **Replace Data Value with Object**: Replace primitive data with an object → [reference](references/replace-data-value-with-object.md)
- **Change Value to Reference**: Convert value objects into reference objects → [reference](references/change-value-to-reference.md)
- **Change Reference to Value**: Convert reference objects into value objects → [reference](references/change-reference-to-value.md)
- **Replace Array with Object**: Swap arrays used as data structures for proper objects → [reference](references/replace-array-with-object.md)
- **Duplicate Observed Data**: Keep domain data in sync with the UI via Observer → [reference](references/duplicate-observed-data.md)
- **Change Unidirectional to Bidirectional**: Introduce back-references when needed → [reference](references/change-unidirectional-association-to-bidirectional.md)
- **Change Bidirectional to Unidirectional**: Eliminate unnecessary back-references → [reference](references/change-bidirectional-association-to-unidirectional.md)
- **Replace Magic Number with Symbolic Constant**: Assign meaningful names to magic numbers → [reference](references/replace-magic-number-with-symbolic-constant.md)
- **Encapsulate Field**: Restrict field visibility and expose accessors → [reference](references/encapsulate-field.md)
- **Encapsulate Collection**: Expose read-only views of collections → [reference](references/encapsulate-collection.md)
- **Replace Type Code with Class**: Swap type codes for enums or classes → [reference](references/replace-type-code-with-class.md)
- **Replace Type Code with Subclasses**: Swap type codes for a class hierarchy → [reference](references/replace-type-code-with-subclasses.md)
- **Replace Type Code with State/Strategy**: Swap behavior-affecting type codes for State/Strategy → [reference](references/replace-type-code-with-state-strategy.md)
- **Replace Subclass with Fields**: Eliminate subclasses that differ only in constants → [reference](references/replace-subclass-with-fields.md)

### Simplifying conditional expressions
- **Decompose Conditional**: Break complex conditionals into named methods → [reference](references/decompose-conditional.md)
- **Consolidate Conditional Expression**: Merge conditions that produce the same result → [reference](references/consolidate-conditional-expression.md)
- **Consolidate Duplicate Conditional Fragments**: Hoist identical code outside of conditionals → [reference](references/consolidate-duplicate-conditional-fragments.md)
- **Remove Control Flag**: Swap control flags for break/return/continue → [reference](references/remove-control-flag.md)
- **Replace Nested Conditional with Guard Clauses**: Flatten nested conditionals using early returns → [reference](references/replace-nested-conditional-with-guard-clauses.md)
- **Replace Conditional with Polymorphism**: Swap conditionals for polymorphic method calls → [reference](references/replace-conditional-with-polymorphism.md)
- **Introduce Null Object**: Swap null checks for a null object → [reference](references/introduce-null-object.md)
- **Introduce Assertion**: Insert assertions to document assumptions → [reference](references/introduce-assertion.md)

### Simplifying method calls
- **Rename Method**: Choose method names that reveal their purpose → [reference](references/rename-method.md)
- **Add Parameter**: Introduce new parameters to support additional data → [reference](references/add-parameter.md)
- **Remove Parameter**: Drop unused method parameters → [reference](references/remove-parameter.md)
- **Separate Query from Modifier**: Divide methods that both return values and change state → [reference](references/separate-query-from-modifier.md)
- **Parameterize Method**: Unify similar methods by adding a parameter → [reference](references/parameterize-method.md)
- **Replace Parameter with Explicit Methods**: Produce separate methods for each parameter value → [reference](references/replace-parameter-with-explicit-methods.md)
- **Preserve Whole Object**: Pass the entire object instead of individual values → [reference](references/preserve-whole-object.md)
- **Replace Parameter with Method Call**: Derive values internally instead of passing them in → [reference](references/replace-parameter-with-method-call.md)
- **Introduce Parameter Object**: Bundle related parameters into an object → [reference](references/introduce-parameter-object.md)
- **Remove Setting Method**: Eliminate setters for fields assigned only at creation → [reference](references/remove-setting-method.md)
- **Hide Method**: Narrow the visibility of unused public methods → [reference](references/hide-method.md)
- **Replace Constructor with Factory Method**: Use factory methods for complex object creation → [reference](references/replace-constructor-with-factory-method.md)
- **Replace Error Code with Exception**: Throw exceptions instead of returning error codes → [reference](references/replace-error-code-with-exception.md)
- **Replace Exception with Test**: Validate conditions upfront instead of catching exceptions → [reference](references/replace-exception-with-test.md)

### Dealing with generalization
- **Pull Up Field**: Promote identical fields to the superclass → [reference](references/pull-up-field.md)
- **Pull Up Method**: Promote identical methods to the superclass → [reference](references/pull-up-method.md)
- **Pull Up Constructor Body**: Promote shared constructor logic to the superclass → [reference](references/pull-up-constructor-body.md)
- **Push Down Method**: Move a method to the subclass that uses it → [reference](references/push-down-method.md)
- **Push Down Field**: Move a field to the subclass that uses it → [reference](references/push-down-field.md)
- **Extract Subclass**: Create a subclass for a subset of features → [reference](references/extract-subclass.md)
- **Extract Superclass**: Move shared behavior into a parent class → [reference](references/extract-superclass.md)
- **Extract Interface**: Define a shared interface for common operations → [reference](references/extract-interface.md)
- **Collapse Hierarchy**: Merge superclass and subclass when they are too similar → [reference](references/collapse-hierarchy.md)
- **Form Template Method**: Generalize similar methods into a template → [reference](references/form-template-method.md)
- **Replace Inheritance with Delegation**: Swap inheritance for composition → [reference](references/replace-inheritance-with-delegation.md)
- **Replace Delegation with Inheritance**: Swap excessive delegation for inheritance → [reference](references/replace-delegation-with-inheritance.md)

## Code smells (22)

### Bloaters
- **Long Method**: Methods that have grown too long → [reference](references/long-method.md)
- **Large Class**: Classes that try to handle too much → [reference](references/large-class.md)
- **Primitive Obsession**: Overuse of primitives instead of small objects → [reference](references/primitive-obsession.md)
- **Long Parameter List**: Methods accepting too many parameters → [reference](references/long-parameter-list.md)
- **Data Clumps**: Groups of data that repeatedly appear together → [reference](references/data-clumps.md)

### Object-Orientation Abusers
- **Alternative Classes with Different Interfaces**: Similar classes with mismatched method signatures → [reference](references/alternative-classes-with-different-interfaces.md)
- **Refused Bequest**: Subclasses that disregard inherited behavior → [reference](references/refused-bequest.md)
- **Switch Statements**: Complex switch/match constructs that should be polymorphism → [reference](references/switch-statements.md)
- **Temporary Field**: Fields populated only under certain conditions → [reference](references/temporary-field.md)

### Change Preventers
- **Divergent Change**: A single class modified for many unrelated reasons → [reference](references/divergent-change.md)
- **Parallel Inheritance Hierarchies**: Creating one subclass forces creating another → [reference](references/parallel-inheritance-hierarchies.md)
- **Shotgun Surgery**: A single change demands edits across many classes → [reference](references/shotgun-surgery.md)

### Dispensables
- **Comments**: Comments that mask unclear code → [reference](references/comments.md)
- **Duplicate Code**: Identical or nearly identical code in multiple locations → [reference](references/duplicate-code.md)
- **Data Class**: Classes consisting of nothing but fields and getters/setters → [reference](references/data-class.md)
- **Dead Code**: Unreachable or unused code → [reference](references/dead-code.md)
- **Lazy Class**: Classes that do too little to justify their existence → [reference](references/lazy-class.md)
- **Speculative Generality**: Unused abstractions built "just in case" → [reference](references/speculative-generality.md)

### Couplers
- **Feature Envy**: Methods that rely more on another class's data than their own → [reference](references/feature-envy.md)
- **Inappropriate Intimacy**: Classes that reach into each other's internals → [reference](references/inappropriate-intimacy.md)
- **Incomplete Library Class**: Library classes that fall short of providing needed features → [reference](references/incomplete-library-class.md)
- **Message Chains**: Long chains of method calls (a.b().c().d()) → [reference](references/message-chains.md)
- **Middle Man**: Classes that do nothing but delegate to another class → [reference](references/middle-man.md)

## Best practices

- Refactor in small, verified steps: run the tests after every change
- Follow the Boy Scout Rule: leave code in better shape than you found it
- Use IDE refactoring tools when available for safe, automated transformations
- Never refactor and alter behavior simultaneously: keep them separate
- Prioritize refactoring that lowers coupling and raises cohesion
- Tackle code smells nearest to your current work first
Files in this package (90)
  • SKILL.md 13 KB
  • references/add-parameter.md 5 KB
  • references/alternative-classes-with-different-interfaces.md 5 KB
  • references/change-bidirectional-association-to-unidirectional.md 6 KB
  • references/change-reference-to-value.md 6 KB
  • references/change-unidirectional-association-to-bidirectional.md 6 KB
  • references/change-value-to-reference.md 7 KB
  • references/collapse-hierarchy.md 5 KB
  • references/comments.md 6 KB
  • references/consolidate-conditional-expression.md 7 KB
  • references/consolidate-duplicate-conditional-fragments.md 6 KB
  • references/data-class.md 7 KB
  • references/data-clumps.md 6 KB
  • references/dead-code.md 6 KB
  • references/decompose-conditional.md 7 KB
  • references/divergent-change.md 7 KB
  • references/duplicate-code.md 7 KB
  • references/duplicate-observed-data.md 8 KB
  • references/encapsulate-collection.md 6 KB
  • references/encapsulate-field.md 7 KB
  • references/extract-class.md 7 KB
  • references/extract-interface.md 7 KB
  • references/extract-method.md 8 KB
  • references/extract-subclass.md 8 KB
  • references/extract-superclass.md 9 KB
  • references/extract-variable.md 8 KB
  • references/feature-envy.md 6 KB
  • references/form-template-method.md 9 KB
  • references/hide-delegate.md 6 KB
  • references/hide-method.md 4 KB
  • references/inappropriate-intimacy.md 7 KB
  • references/incomplete-library-class.md 6 KB
  • references/inline-class.md 5 KB
  • references/inline-method.md 8 KB
  • references/inline-temp.md 6 KB
  • references/introduce-assertion.md 7 KB
  • references/introduce-foreign-method.md 10 KB
  • references/introduce-local-extension.md 10 KB
  • references/introduce-null-object.md 7 KB
  • references/introduce-parameter-object.md 5 KB
  • references/large-class.md 7 KB
  • references/lazy-class.md 6 KB
  • references/long-method.md 7 KB
  • references/long-parameter-list.md 7 KB
  • references/message-chains.md 6 KB
  • references/middle-man.md 5 KB
  • references/move-field.md 7 KB
  • references/move-method.md 6 KB
  • references/parallel-inheritance-hierarchies.md 5 KB
  • references/parameterize-method.md 4 KB
  • references/preserve-whole-object.md 6 KB
  • references/primitive-obsession.md 7 KB
  • references/pull-up-constructor-body.md 7 KB
  • references/pull-up-field.md 8 KB
  • references/pull-up-method.md 5 KB
  • references/push-down-field.md 5 KB
  • references/push-down-method.md 5 KB
  • references/refused-bequest.md 6 KB
  • references/remove-assignments-to-parameters.md 7 KB
  • references/remove-control-flag.md 5 KB
  • references/remove-middle-man.md 5 KB
  • references/remove-parameter.md 4 KB
  • references/remove-setting-method.md 4 KB
  • references/rename-method.md 5 KB
  • references/replace-array-with-object.md 6 KB
  • references/replace-conditional-with-polymorphism.md 8 KB
  • references/replace-constructor-with-factory-method.md 6 KB
  • references/replace-data-value-with-object.md 8 KB
  • references/replace-delegation-with-inheritance.md 6 KB
  • references/replace-error-code-with-exception.md 6 KB
  • references/replace-exception-with-test.md 5 KB
  • references/replace-inheritance-with-delegation.md 7 KB
  • references/replace-magic-number-with-symbolic-constant.md 8 KB
  • references/replace-method-with-method-object.md 9 KB
  • references/replace-nested-conditional-with-guard-clauses.md 8 KB
  • references/replace-parameter-with-explicit-methods.md 7 KB
  • references/replace-parameter-with-method-call.md 5 KB
  • references/replace-subclass-with-fields.md 5 KB
  • references/replace-temp-with-query.md 8 KB
  • references/replace-type-code-with-class.md 7 KB
  • references/replace-type-code-with-state-strategy.md 6 KB
  • references/replace-type-code-with-subclasses.md 7 KB
  • references/self-encapsulate-field.md 7 KB
  • references/separate-query-from-modifier.md 4 KB
  • references/shotgun-surgery.md 5 KB
  • references/speculative-generality.md 6 KB
  • references/split-temporary-variable.md 6 KB
  • references/substitute-algorithm.md 8 KB
  • references/switch-statements.md 6 KB
  • references/temporary-field.md 6 KB

Versions

RepositoryScoreLicence
This page · krzysztofsurdy/code-virtuoso100MIT
gabrieldulolmarques/refactoring-skill100CC-BY-4.0
4typen/skills100MIT
t8jwscc7qy-sketch/foma-skills100Apache-2.0
mtwuser/zero-cloud-gravity100MIT
sagargupta16/claude-skills100MIT
nimadorostkar/Claude-Skills-collection100MIT
DariuszDusza/agentic-workflow-foundry100Apache-2.0
0xsarwagya/ontoly100AGPL-3.0

Database snapshot: 13.11.2026 · package version 7c361fd574b7 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100refactoring-advisor
    Analyze code for structural issues and code smells, then recommend prioritized refactoring patterns with before/after examples. Use when the user asks to refactor, clean up, or improve code structure, when a module has grown hard to change or test, or when a review surfaces maintainability problems.
  • 93code-quality
    two-stage review (spec compliance first, then code quality), refactoring, and quality improvement. Use when reviewing code, eliminating code smells, reducing technical debt, refactoring methods, running self-critique loops, or improving maintainability and readability.
  • 100python-refactoring
    Python refactoring catalog with 83 patterns covering immutability, class design, control flow, architecture, OO metrics, and Python idioms. Analyze code for smells and apply numbered refactoring patterns with before/after examples. Use when the user invokes /refactor or…
  • 100coding-standards
    Detects code smells, anti-patterns, and readability issues. Use when implementing features, reviewing code, or refactoring.
  • 100tech-debt-analyzer
    This skill should be used when analyzing technical debt in a codebase, documenting code quality issues, creating technical debt registers, or assessing code maintainability. Use this for identifying code smells, architectural issues, dependency problems, missing documentation,…
  • 100refactor
    Analyze complexity and smells, draft a safe refactor plan, and execute step-by-step with tests. Use when refactoring code or invoking /refactor.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.