open-closed-principle

Refactor branching conditionals into strategy-based designs with interchangeable variants.

13|2|Updated Jan 21, 2026
One-click install
npx skills add https://github.com/yanko-belov/code-craft --skill open-closed-principle
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: open-closed-principle
Source: https://github.com/yanko-belov/code-craft/tree/main/skills/open-closed
Command: npx skills add https://github.com/yanko-belov/code-craft --skill open-closed-principle

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers avoid modifying working code when adding new features, preventing regression and churn by promoting design that is open for extension but closed for modification.

Core Features & Use Cases

  • Promotes safe extensions by guiding the extraction of interfaces and creation of new variants instead of altering existing branches.
  • Prevents feature drift by encouraging a strategy or plugin pattern that keeps core logic intact.
  • Use Case: When adding a new notification channel, implement a new class that conforms to an existing interface rather than adding an else/if branch.

Quick Start

Refactor a branching conditional into a strategy-based design and register the new variant without modifying the existing code paths.

Frequently Asked Questions about open-closed-principle

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

FAQPage Schema
How do I add new payment methods without modifying existing code branches?

To add new payment methods without modifying existing code, you extract an interface from the current conditional branches and implement the new variants as separate classes. These classes are then registered or injected so the core logic remains unchanged and avoids regression.

What is the open-closed principle in software design?

The open-closed principle in software design states that modules should be open for extension but closed for modification. It prevents feature drift and regression by encouraging a strategy or plugin pattern, allowing you to add new variants without altering working core logic.

How do I refactor branching conditionals into a strategy pattern?

To refactor branching conditionals into a strategy pattern, you identify existing if/else branches, extract a common interface, and implement each branch as a separate class. You then register or inject these new variants so the core logic can use them without being modified.

When do I need to apply the open-closed principle during refactoring?

You need to apply the open-closed principle during refactoring when you must support new variants, such as export formats or notification channels, without altering current branches. It is used to prevent regression and churn by keeping the core logic intact while safely extending behavior.

What is the best way to support new export formats without causing regression?

The best way to support new export formats without causing regression is to implement a new class that conforms to an existing interface rather than adding an else/if branch. This strategy-based design keeps core logic intact and prevents feature drift during extension.

Why does adding else/if branches cause feature drift in software extensions?

Adding else/if branches causes feature drift because it forces you to modify working core logic, increasing the risk of regression and churn. The open-closed principle prevents this by encouraging a plugin pattern where new variants are implemented as separate injected classes.