refactoring-patterns

Apply named refactoring transformations to restructure code without changing behavior.

Updated Jul 8, 2026
One-click install
npx skills add https://github.com/HafidJoss/Lummy --skill refactoring-patterns-hafidjoss
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactoring-patterns
Source: https://github.com/HafidJoss/Lummy/tree/main/agent/skills/refactoring-patterns
Command: npx skills add https://github.com/HafidJoss/Lummy --skill refactoring-patterns-hafidjoss

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, and misplaced responsibilities—that slow down every future change. This Skill provides a disciplined, smell-driven approach to identifying structural problems and applying the correct named refactoring safely, with tests as a guard at every step. ## Core Features & Use Cases - Smell-Driven Diagnosis: Identify code smells across five families (Bloaters, OO Abusers, Change Preventers, Dispensables, Couplers) and map each to its prescribed refactoring. - Named Transformation Catalogs: Step-by-step mechanics for Composing Methods, Moving Features Between Objects, Organizing Data, and Simplifying Conditional Logic, each with before/after code examples. - Safe Workflow Discipline: Enforce the green-to-green refactoring cycle, the Two Hats rule, the Rule of Three, and large-scale strategies like Branch by Abstraction and Parallel Change. - Use Case: You inherit a 500-line God class with a switch statement duplicated in four methods. Use this Skill to name the smells (Large Class, Switch Statements), then apply Extract Class and Replace Conditional with Polymorphism in small, test-verified steps. ## Quick Start Ask the AI to review this messy function, name the code smells it contains, and refactor it step by step while keeping the tests green.

Frequently Asked Questions about refactoring-patterns

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

FAQPage Schema
How do I refactor legacy code safely without breaking it?

Refactor legacy code safely by first writing characterization tests that capture current behavior, then applying one small transformation at a time. Run tests after every step, and revert immediately if any test fails rather than debugging a broken refactoring.

What is the best refactoring for long methods?

Extract Method is the primary refactoring for long methods: pull each logical section into its own well-named method. If tangled local variables block extraction, use Replace Method with Method Object to turn locals into fields first.

When should I replace a switch statement with polymorphism?

Replace Conditional with Polymorphism when the same type-based switch or if/else chain appears in multiple methods and new types are added frequently. If the conditional appears only once with a small fixed set of types, Decompose Conditional is usually sufficient.

When should you not refactor code?

Avoid refactoring when a rewrite is simpler, when no tests exist and adding them is impractical, when the code will be deleted soon, or when it is throwaway prototype code. Also never refactor and add features in the same step.

How do I fix duplicated code across multiple classes?

Fix duplicated code by applying Extract Method to isolate the shared logic, then Pull Up Method to move it into a common base class, or Extract Class when the duplication spans unrelated classes. Follow the Rule of Three: refactor on the third occurrence.