refactoring-patterns

Apply named refactoring transformations to improve code structure without changing behavior.

Updated Jun 27, 2026
One-click install
npx skills add https://github.com/rachmadideni/ai-staff-assistant --skill refactoring-patterns-rachmadideni
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: refactoring-patterns
Source: https://github.com/rachmadideni/ai-staff-assistant/tree/main/.agents/skills/refactoring-patterns
Command: npx skills add https://github.com/rachmadideni/ai-staff-assistant --skill refactoring-patterns-rachmadideni

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Legacy and rushed code accumulates structural problems—long methods, duplicated logic, tangled conditionals—that slow down every future change. This Skill provides a disciplined, catalog-driven approach to identifying code smells and applying the exact named refactoring that fixes each one, all while keeping tests green so behavior never changes. ## Core Features & Use Cases - Smell-Driven Diagnosis: Maps the five code smell families (Bloaters, OO Abusers, Change Preventers, Dispensables, Couplers) to their prescribed refactorings, so you fix root causes instead of guessing. - Full Refactoring Catalog: Covers Composing Methods, Moving Features Between Objects, Organizing Data, and Simplifying Conditional Logic with step-by-step mechanics and before/after code examples. - Safe Workflow Discipline: Enforces the green-test → small change → green-test → commit cycle, plus large-scale strategies like Branch by Abstraction and Parallel Change for production systems. - Use Case: You inherit a 500-line Order class with a switch statement on customer type repeated in four methods. The Skill identifies Feature Envy and Switch Statements smells, then walks you through Move Method and Replace Conditional with Polymorphism, one tested step at a time. ## Quick Start Ask the assistant to review this messy function, name the code smells it contains, and refactor it step by step without changing its behavior.

Frequently Asked Questions about refactoring-patterns

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

FAQPage Schema
How do I refactor a long method safely?▼

Refactor a long method by applying Extract Method: pull each logical section into its own well-named method, passing needed locals as parameters. Run tests after every extraction and commit only when all tests pass, so any failure points to the last small step.

What is the best way to fix duplicated code?▼

Fix duplicated code with Extract Method to share common logic, or Pull Up Method when duplication spans sibling classes. Follow the Rule of Three: tolerate duplication once, note it twice, and refactor on the third occurrence to avoid premature abstraction.

When should I replace a switch statement with polymorphism?▼

Replace a switch statement with polymorphism when the same type-based conditional appears in multiple methods and new types are added frequently. Each type gets its own subclass implementing the behavior, so adding a type means adding a class instead of editing scattered conditionals.

Can I refactor code that has no tests?▼

Refactoring without tests is unsafe because you cannot verify behavior is preserved. First write characterization tests that capture the code's current actual outputs, even if they seem wrong, then refactor freely behind that safety net.

When should I not refactor code?▼

Avoid refactoring when a rewrite is genuinely easier, when the code will be deleted soon, when no tests exist and adding them is impractical, or when the code works and nobody needs to modify it. Polish on doomed or untouched code wastes effort.

How do I make a large refactoring without a long-lived branch?▼

Use Branch by Abstraction: introduce an interface over the old component, migrate callers incrementally, build the new implementation behind the abstraction, then switch over and delete the old code. Parallel Change works similarly for renaming widely-used APIs via expand, migrate, and contract phases.