refactoring-direction

Enforces instance-based, interface-driven refactoring rules across Gum source projects.

614|78|Updated Mar 11, 2015
One-click install
npx skills add https://github.com/vchelaru/Gum --skill refactoring-direction
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactoring-direction
Source: https://github.com/vchelaru/Gum/tree/main/.claude/skills/refactoring-direction
Command: npx skills add https://github.com/vchelaru/Gum --skill refactoring-direction

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

When refactoring the Gum codebase, contributors risk moving code in the wrong architectural direction — promoting members to static, demoting interfaces to concrete types, or bloating god classes like GraphicalUiElement — which undoes the project's ongoing migration from static singletons to constructor-injected services.

Core Features & Use Cases

  • Directional refactoring rules: Mandates moving toward instances, interfaces, and single-responsibility classes, and never toward statics or concrete types.
  • Singleton drain guidance: Defines which singletons are sanctioned exceptions (ObjectFinder.Self, RenderingLibrary/InputLibrary runtime singletons) versus in-scope drain targets, including MEF plugin injection patterns and Lazy<T> cycle-breaking.
  • Testability discipline: Requires that extraction-for-testability refactors ship with a test, and calibrates when characterization tests add value during behavior-preserving drains.
  • Use Case: While extracting duplicated Gradient/Dropshadow logic shared by CircleRuntime and RectangleRuntime, apply the composed-struct pattern (no cached mutable references) instead of adding methods to a shared base class that cannot exist.

Quick Start

Ask the AI to review a proposed refactor of a Gum manager class and confirm it follows the refactoring-direction rules before making the changes.

Frequently Asked Questions about refactoring-direction

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

FAQPage Schema
How do I refactor a static singleton to constructor injection in C#?

Replace the .Self access with a constructor-injected interface parameter and register the service in the DI container. If a construction cycle appears at startup, inject the back-edge dependency as Lazy<T> and access .Value at call time.

When should I extract a new class instead of adding to an existing one?

Extract a new single-responsibility class whenever new behavior would grow a large class like GraphicalUiElement or CodeGenerator, even if the new class starts with one method. The existing class should compose with the new controller or service.

Is it ever acceptable to make a method static in the Gum codebase?

No. Instance members must never be promoted to static, even if they currently hold no instance state. Sanctioned existing singletons like ObjectFinder.Self and RenderingLibrary runtime singletons may remain, but no new statics should be introduced.

How do I break a dependency injection construction cycle?

Inject the cycling dependency as Lazy<T>, which the DI container resolves, and access .Value after construction completes. Prefer lazying the consumer's edge to the drained class so multi-hop cycles through a third class are also broken.

Does a behavior-preserving singleton drain require new tests?

Usually the compiler and DI container already verify a drain, since injection wiring is type-checked and cycles throw at startup. Add a characterization test only where the injected seam is clean and the assertion is meaningful.

How do MEF plugins receive injected services instead of using a service locator?

Bridge the service into the MEF container in PluginManager.LoadPlugins via batch.AddExportedValue<T>, then inject it through an [ImportingConstructor] parameter or a settable [Import] property. The Locator call moves to the composition root rather than disappearing.