refactoring-catalog

Identifies code smells and applies refactoring techniques from Martin Fowler's catalog. Use when improving code structure, reducing complexity, or eliminating smells without changing behavior.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "refactoring-catalog" with this command: npx skills add emvnuel/skill.md/emvnuel-skill-md-refactoring-catalog

Refactoring Catalog

Systematic techniques for improving code structure without changing its observable behavior. Based on Martin Fowler's Refactoring Catalog.


Composing Methods

Extract Function

Smell: Long method, code fragment that can be grouped
Action: Turn the fragment into a method with a name explaining its purpose
Cookbook: extract-function.md

Inline Function

Smell: Function body is as clear as its name
Action: Replace calls with the function body and remove the function
Cookbook: inline-function.md

Extract Variable

Smell: Complex expression that's hard to understand
Action: Place the result in a temporary variable with a meaningful name
Cookbook: extract-variable.md

Inline Variable

Smell: Variable name doesn't communicate more than the expression
Action: Replace references with the expression itself
Cookbook: inline-variable.md

Replace Temp with Query

Smell: Temporary variable holding the result of an expression
Action: Extract the expression into a method and replace temp with query
Cookbook: replace-temp-with-query.md

Split Variable

Smell: Variable assigned more than once (not a loop variable)
Action: Make a separate variable for each assignment
Cookbook: split-variable.md


Moving Features

Move Function

Smell: Function references elements from another context more than its own
Action: Move it to the context it references most
Cookbook: move-function.md

Move Field

Smell: Field used more by another class than its own
Action: Move it to the class that uses it most
Cookbook: move-field.md

Move Statements into Function

Smell: Same code executed around a function call
Action: Move those statements into the function
Cookbook: move-statements-into-function.md

Move Statements to Callers

Smell: Function with behavior that some callers don't need
Action: Move the varying behavior to the callers
Cookbook: move-statements-to-callers.md

Replace Inline Code with Function Call

Smell: Inline code doing the same thing as an existing function
Action: Replace with a call to the function
Cookbook: replace-inline-code-with-function-call.md

Slide Statements

Smell: Related code fragments not next to each other
Action: Slide statements to be adjacent
Cookbook: slide-statements.md

Split Loop

Smell: Loop doing multiple things
Action: Split into separate loops for each task
Cookbook: split-loop.md

Split Phase

Smell: Code dealing with two different things
Action: Split into separate phases with intermediate data structure
Cookbook: split-phase.md


Organizing Data

Replace Primitive with Object

Smell: Primitive used to represent a domain concept
Action: Create a class with the primitive as its data
Cookbook: replace-primitive-with-object.md

Change Value to Reference

Smell: Multiple copies of the same conceptual data
Action: Replace copies with a single reference object
Cookbook: change-value-to-reference.md

Change Reference to Value

Smell: Reference object that's hard to work with
Action: Replace with a value object
Cookbook: change-reference-to-value.md

Replace Magic Literal

Smell: Literal with special meaning that's not obvious
Action: Replace with a named constant
Cookbook: replace-magic-literal.md

Rename Variable

Smell: Variable name doesn't clearly communicate its purpose
Action: Change the name to something more communicative
Cookbook: rename-variable.md

Rename Field

Smell: Field name doesn't clearly communicate its purpose
Action: Change the name to something more communicative
Cookbook: rename-field.md

Change Function Declaration

Smell: Function name/parameters don't clearly communicate purpose
Action: Rename function and/or add/remove parameters
Cookbook: change-function-declaration.md

Encapsulate Variable

Smell: Public field accessed directly
Action: Create getter/setter functions
Cookbook: encapsulate-variable.md

Encapsulate Collection

Smell: Collection returned directly, allowing modification
Action: Return a copy or read-only view
Cookbook: encapsulate-collection.md

Encapsulate Record

Smell: Record/hash used for mutable data
Action: Create a class with accessors
Cookbook: encapsulate-record.md


Simplifying Conditional Logic

Decompose Conditional

Smell: Complex conditional (if-else) with complicated conditions
Action: Extract condition and each branch into separate functions
Cookbook: decompose-conditional.md

Consolidate Conditional Expression

Smell: Multiple conditionals with the same result
Action: Combine them into a single conditional
Cookbook: consolidate-conditional-expression.md

Replace Nested Conditional with Guard Clauses

Smell: Deeply nested if-else structure
Action: Use guard clauses for special cases, return early
Cookbook: replace-nested-conditional-with-guard-clauses.md

Replace Conditional with Polymorphism

Smell: Switch/if-else selecting behavior based on type
Action: Create subclasses and override methods
Cookbook: replace-conditional-with-polymorphism.md

Introduce Special Case

Smell: Many places check for a special value (often null)
Action: Create a special case object encapsulating the behavior
Cookbook: introduce-special-case.md

Introduce Assertion

Smell: Code assumes something about program state
Action: Make the assumption explicit with an assertion
Cookbook: introduce-assertion.md

Replace Control Flag with Break

Smell: Boolean variable controlling loop exit
Action: Use break, continue, or return instead
Cookbook: replace-control-flag-with-break.md

Replace Exception with Precheck

Smell: Exception used for expected condition
Action: Check the condition first
Cookbook: replace-exception-with-precheck.md


Refactoring APIs

Separate Query from Modifier

Smell: Function that returns a value and has side effects
Action: Create two functions: one for query, one for modifier
Cookbook: separate-query-from-modifier.md

Parameterize Function

Smell: Multiple functions doing similar things with literals
Action: Combine into one function with a parameter
Cookbook: parameterize-function.md

Remove Flag Argument

Smell: Boolean argument that changes function behavior
Action: Create separate functions for each case
Cookbook: remove-flag-argument.md

Preserve Whole Object

Smell: Passing several values from one object to a function
Action: Pass the whole object instead
Cookbook: preserve-whole-object.md

Replace Parameter with Query

Smell: Parameter that can be derived from another parameter
Action: Remove the parameter and let the function calculate it
Cookbook: replace-parameter-with-query.md

Replace Query with Parameter

Smell: Function references a global or internal value directly
Action: Pass the value as a parameter
Cookbook: replace-query-with-parameter.md

Remove Setting Method

Smell: Field should be set at construction time only
Action: Remove the setter and set in constructor
Cookbook: remove-setting-method.md

Replace Constructor with Factory Function

Smell: Constructor has limitations (name, return type)
Action: Replace with a factory function
Cookbook: replace-constructor-with-factory-function.md

Replace Function with Command

Smell: Function needs to be undone, queued, or has complex state
Action: Encapsulate the function in a command object
Cookbook: replace-function-with-command.md

Replace Command with Function

Smell: Command object is too simple
Action: Replace with a plain function
Cookbook: replace-command-with-function.md

Return Modified Value

Smell: Function updates data but doesn't return it
Action: Return the modified value
Cookbook: return-modified-value.md

Replace Error Code with Exception

Smell: Function returns error code to indicate failure
Action: Throw an exception instead
Cookbook: replace-error-code-with-exception.md

Introduce Parameter Object

Smell: Group of parameters that travel together
Action: Replace them with an object
Cookbook: introduce-parameter-object.md


Dealing with Inheritance

Pull Up Method

Smell: Identical methods in sibling classes
Action: Move to the superclass
Cookbook: pull-up-method.md

Pull Up Field

Smell: Identical field in sibling classes
Action: Move to the superclass
Cookbook: pull-up-field.md

Pull Up Constructor Body

Smell: Constructors in subclasses have common code
Action: Move common code to superclass constructor
Cookbook: pull-up-constructor-body.md

Push Down Method

Smell: Method only relevant to one subclass
Action: Move it to that subclass
Cookbook: push-down-method.md

Push Down Field

Smell: Field only used by one subclass
Action: Move it to that subclass
Cookbook: push-down-field.md

Replace Type Code with Subclasses

Smell: Field/parameter that indicates type with conditional behavior
Action: Replace with subclasses
Cookbook: replace-type-code-with-subclasses.md

Remove Subclass

Smell: Subclass does too little to justify its existence
Action: Replace with a field in the superclass
Cookbook: remove-subclass.md

Extract Superclass

Smell: Multiple classes with similar features
Action: Create a superclass with the common elements
Cookbook: extract-superclass.md

Collapse Hierarchy

Smell: Subclass is no different from its superclass
Action: Merge them together
Cookbook: collapse-hierarchy.md

Replace Subclass with Delegate

Smell: Inheritance used for a single axis of variation
Action: Replace with a delegate field
Cookbook: replace-subclass-with-delegate.md

Replace Superclass with Delegate

Smell: Subclass doesn't want all of superclass behavior
Action: Replace inheritance with delegation
Cookbook: replace-superclass-with-delegate.md

Extract Class

Smell: Class doing too much, has too many responsibilities
Action: Split into two classes
Cookbook: extract-class.md


Other Refactorings

Inline Class

Smell: Class does too little to justify its existence
Action: Move all features to another class
Cookbook: inline-class.md

Hide Delegate

Smell: Client calls through one object to reach another
Action: Create a delegating method
Cookbook: hide-delegate.md

Remove Middle Man

Smell: Class has too many simple delegating methods
Action: Let clients call the delegate directly
Cookbook: remove-middle-man.md

Substitute Algorithm

Smell: Algorithm can be replaced with a clearer one
Action: Replace the body with the new algorithm
Cookbook: substitute-algorithm.md

Combine Functions into Class

Smell: Group of functions operating on the same data
Action: Form a class with the data and functions
Cookbook: combine-functions-into-class.md

Combine Functions into Transform

Smell: Reading data, computing derived values, passing around
Action: Create a transform function that enriches the data
Cookbook: combine-functions-into-transform.md

Replace Loop with Pipeline

Smell: Loop processing a collection
Action: Replace with pipeline operations (map, filter, reduce)
Cookbook: replace-loop-with-pipeline.md

Remove Dead Code

Smell: Code that's never executed
Action: Delete it
Cookbook: remove-dead-code.md

Replace Derived Variable with Query

Smell: Variable calculated from other values and stored
Action: Calculate it on demand
Cookbook: replace-derived-variable-with-query.md


Quick Reference Table

CategoryRefactoringPrimary Smell
Composing MethodsExtract FunctionLong method, code fragment
Composing MethodsInline FunctionTrivial function body
Composing MethodsExtract VariableComplex expression
Composing MethodsInline VariableUnnecessary variable
Composing MethodsReplace Temp with QueryTemp holding expression
Composing MethodsSplit VariableMultiple assignments
Moving FeaturesMove FunctionFeature envy
Moving FeaturesMove FieldField envy
Moving FeaturesMove Statements into FunctionRepeated code around call
Moving FeaturesMove Statements to CallersVarying behavior in function
Moving FeaturesReplace Inline Code with Function CallDuplicate logic
Moving FeaturesSlide StatementsSeparated related code
Moving FeaturesSplit LoopLoop doing multiple things
Moving FeaturesSplit PhaseMixed concerns
Organizing DataReplace Primitive with ObjectPrimitive obsession
Organizing DataChange Value to ReferenceInconsistent data
Organizing DataChange Reference to ValueComplex reference handling
Organizing DataReplace Magic LiteralMysterious numbers
Organizing DataRename VariableUnclear naming
Organizing DataRename FieldUnclear naming
Organizing DataChange Function DeclarationBad signature
Organizing DataEncapsulate VariablePublic field
Organizing DataEncapsulate CollectionExposed collection
Organizing DataEncapsulate RecordNaked record
Simplifying ConditionalsDecompose ConditionalComplex conditional
Simplifying ConditionalsConsolidate Conditional ExpressionDuplicate conditions
Simplifying ConditionalsReplace Nested Conditional with Guard ClausesDeep nesting
Simplifying ConditionalsReplace Conditional with PolymorphismType-based switching
Simplifying ConditionalsIntroduce Special CaseNull checks
Simplifying ConditionalsIntroduce AssertionHidden assumptions
Simplifying ConditionalsReplace Control Flag with BreakControl flag
Simplifying ConditionalsReplace Exception with PrecheckException for expected case
Refactoring APIsSeparate Query from ModifierMixed query/command
Refactoring APIsParameterize FunctionSimilar functions
Refactoring APIsRemove Flag ArgumentBoolean argument
Refactoring APIsPreserve Whole ObjectData clump
Refactoring APIsReplace Parameter with QueryDerivable parameter
Refactoring APIsReplace Query with ParameterHidden dependency
Refactoring APIsRemove Setting MethodMutable after construction
Refactoring APIsReplace Constructor with Factory FunctionConstructor limitations
Refactoring APIsReplace Function with CommandComplex function
Refactoring APIsReplace Command with FunctionOver-engineered command
Refactoring APIsReturn Modified ValueSide effect only
Refactoring APIsReplace Error Code with ExceptionError code
Refactoring APIsIntroduce Parameter ObjectData clump
Dealing with InheritancePull Up MethodDuplicate methods
Dealing with InheritancePull Up FieldDuplicate fields
Dealing with InheritancePull Up Constructor BodyDuplicate constructor code
Dealing with InheritancePush Down MethodUnused in superclass
Dealing with InheritancePush Down FieldUnused field
Dealing with InheritanceReplace Type Code with SubclassesType code
Dealing with InheritanceRemove SubclassTrivial subclass
Dealing with InheritanceExtract SuperclassDuplicate features
Dealing with InheritanceCollapse HierarchyIdentical class levels
Dealing with InheritanceReplace Subclass with DelegateSingle variation axis
Dealing with InheritanceReplace Superclass with DelegatePartial inheritance
Dealing with InheritanceExtract ClassLarge class
OtherInline ClassLazy class
OtherHide DelegateLaw of Demeter violation
OtherRemove Middle ManMessage chain wrapper
OtherSubstitute AlgorithmInferior algorithm
OtherCombine Functions into ClassFeature envy group
OtherCombine Functions into TransformDerived data passing
OtherReplace Loop with PipelineLoop collection processing
OtherRemove Dead CodeDead code
OtherReplace Derived Variable with QueryStored calculation

Cookbook Index

All 66 refactoring techniques with detailed mechanics:

Composing Methods (6): Extract Function · Inline Function · Extract Variable · Inline Variable · Replace Temp with Query · Split Variable

Moving Features (8): Move Function · Move Field · Move Statements into Function · Move Statements to Callers · Replace Inline Code with Function Call · Slide Statements · Split Loop · Split Phase

Organizing Data (10): Replace Primitive with Object · Change Value to Reference · Change Reference to Value · Replace Magic Literal · Rename Variable · Rename Field · Change Function Declaration · Encapsulate Variable · Encapsulate Collection · Encapsulate Record

Simplifying Conditional Logic (8): Decompose Conditional · Consolidate Conditional Expression · Replace Nested Conditional with Guard Clauses · Replace Conditional with Polymorphism · Introduce Special Case · Introduce Assertion · Replace Control Flag with Break · Replace Exception with Precheck

Refactoring APIs (13): Separate Query from Modifier · Parameterize Function · Remove Flag Argument · Preserve Whole Object · Replace Parameter with Query · Replace Query with Parameter · Remove Setting Method · Replace Constructor with Factory Function · Replace Function with Command · Replace Command with Function · Return Modified Value · Replace Error Code with Exception · Introduce Parameter Object

Dealing with Inheritance (12): Pull Up Method · Pull Up Field · Pull Up Constructor Body · Push Down Method · Push Down Field · Replace Type Code with Subclasses · Remove Subclass · Extract Superclass · Collapse Hierarchy · Replace Subclass with Delegate · Replace Superclass with Delegate · Extract Class

Other Refactorings (9): Inline Class · Hide Delegate · Remove Middle Man · Substitute Algorithm · Combine Functions into Class · Combine Functions into Transform · Replace Loop with Pipeline · Remove Dead Code · Replace Derived Variable with Query

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

clean-code-principles

No summary provided by upstream source.

Repository SourceNeeds Review
General

quarkus-panache-smells

No summary provided by upstream source.

Repository SourceNeeds Review
General

lombok-patterns

No summary provided by upstream source.

Repository SourceNeeds Review