Design Pattern Analysis and Refactoring
Paste the following prompt into your AI chat to install this skill:
Install @user_2fd60672/100 into your AI assistant according to https://skillhub.cn/install/skillhub.md.
About this skill
Problem
A lot of code fails not because it throws errors, but because its structure degrades as requirements grow: if-else and switch branches keep expanding, classes grow beyond 300 lines, constructors accumulate parameters, high-level modules directly instantiate concrete classes, interfaces carry unrelated methods, and multiple systems maintain duplicated logic. These issues usually stay quiet until the next change becomes expensive: adjusting one payment branch affects order flow, adding an export format rewrites the report class, or adapting to a legacy interface forces compatibility logic into business code. Design patterns are not decorative vocabulary; they make variation points, object creation, behavior switching, and object collaboration explicit.
How It Works
The skill turns code review into a concrete workflow: detect common code smells, check SRP, OCP, LSP, ISP, and DIP, match the problem to a GoF pattern, and output refactor suggestions tied to the specific issue. It handles typical cases such as replacing conditional object creation with factory methods or abstract factories, using Builder for complex construction, converging runtime behavior switching with Strategy or State, and distinguishing Adapter, Decorator, and Proxy. For easily confused patterns, it gives boundaries: strategy is client-driven algorithm switching, while state is behavior driven by state transitions; template method relies on inheritance and fixes the skeleton at compile time, whereas strategy relies on composition and supports runtime replacement.
Scope
This skill is best for existing code whose structure is becoming hard to maintain, such as branch-heavy logic, mixed responsibilities, tight object creation coupling, or scattered event handling. It is not a license to over-engineer simple code: do not introduce factories where constructors are enough, and do not force abstractions where a plain method would work. Refactoring should preserve backward compatibility, isolate the parts most likely to change, and address one principle violation at a time instead of redrawing the entire system.
Use Cases
- Maintaining a payment service where new channels require scattered if-else branches, decide whether to refactor with Strategy or Factory.
- Inheriting a 300+ line order class, split responsibilities using SRP and identify extractable common logic.
- Integrating a legacy system with incompatible interfaces, evaluate Adapter, Decorator, or Proxy for the right boundary.
- Handling growing order state branches, determine whether State mode fits and outline state transition changes.
Best For
- Backend engineers maintaining payment or order systems who want to replace branch growth with switchable algorithms or factory creation.
- Tech leads inheriting legacy services who need SOLID-based module review and a progressive refactor checklist.
- Engineers integrating external or legacy interfaces who need clear Adapter, Decorator, or Proxy boundaries.
- Senior engineers leading code review who need pattern advice mapped to specific classes and functions.
Related Skills
A one-shot coding agent built on Claude Code CLI that runs non-interactively, supports a specified workdir, and can be monitored in the foreground or background.
Preview and confirm file sorting by extension, with recursive cleanup, ignore rules, and transactional rollback.
An engineering assistant for static HTML/CSS/JS pages, design-token extraction, IE8-compatible review, and structured delivery.
An engineering workflow for requirement analysis, scenario modeling, risk planning, quality gates, testing, and knowledge capture, with lightweight, standard, and full modes.