refactoring-patterns

Apply behavior-preserving refactorings like Extract Function with post-change testing.

9|5|Updated Aug 8, 2025
One-click install
npx skills add https://github.com/AnExiledDev/CodeForge --skill refactoring-patterns-anexileddev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactoring-patterns
Source: https://github.com/AnExiledDev/CodeForge/tree/main/.devcontainer/plugins/devs-marketplace/plugins/code-directive/skills/refactoring-patterns
Command: npx skills add https://github.com/AnExiledDev/CodeForge --skill refactoring-patterns-anexileddev

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps developers apply safe, behavior-preserving refactorings to improve code quality without changing observable behavior. It guides the identification of code smells, selection of appropriate transformations, and validation through tests.

Core Features & Use Cases

  • Safe transformation planning: identify smells and map them to one-at-a-time changes (e.g., Extract Function, Inline Variable, Replace Conditional with Polymorphism).
  • Step-by-step guidance: provides mechanical steps and guardrails to preserve behavior during refactors.
  • Real-world use cases: reduces long methods, Feature Envy, Data Clumps, Primitive Obsession, and God Classes.

Quick Start

Identify the most actionable code smell in your target function and perform one safe, behavior-preserving refactoring, like extracting a function, then re-run tests.

Frequently Asked Questions about refactoring-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely refactor long methods without changing behavior?

Safe refactoring of long methods requires applying one-at-a-time, behavior-preserving transformations like Extract Function. You must identify specific code smells, apply a mechanical change from a defined catalog, and validate the result by re-running tests immediately after each step.

When should I use Replace Conditional with Polymorphism to fix code smells?

Replace Conditional with Polymorphism is used to fix code smells when you have complex conditional logic that varies by type. This refactoring moves conditional behavior into subclasses, reducing duplicated logic and simplifying the main method body while preserving observable behavior.

What is the best way to reduce Feature Envy and Data Clumps during code refactoring?

The best way to reduce Feature Envy and Data Clumps is to identify these code smells and map them to targeted transformations. Extract Function moves behavior to the correct object, while replacing primitive obsessions with proper classes gradually eliminates data clumps.

How do I extract a function from a God Class without breaking existing tests?

To extract a function from a God Class, use the Extract Function refactoring pattern with mechanical guardrails. Move the targeted logic step-by-step, ensuring behavior preservation by validating the transformation against your existing test suite immediately after each extraction.

Why do I need to run tests after every single refactoring step?

Running tests after every single refactoring step is required because transformations must be behavior-preserving. Validating each isolated change immediately catches structural errors before they compound, ensuring the sequence of catalog-applied refactorings maintains the original observable behavior.

Can I inline variables to simplify duplicated logic in my codebase?

Yes, you can inline variables to simplify duplicated logic. Inline Variable is a valid catalog transformation that replaces temporary variables with their direct values, reducing unnecessary indirection and making subsequent refactorings to eliminate duplicated logic easier to apply.