convention-rule-of-three

Identifies duplicated code across modules and triggers refactoring at the third occurrence.

Updated Mar 19, 2026
One-click install
npx skills add https://github.com/sunLeee/optimization --skill convention-rule-of-three
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: convention-rule-of-three
Source: https://github.com/sunLeee/optimization/tree/main/.claude/skills/reference/philosophy/design/rule-of-three
Command: npx skills add https://github.com/sunLeee/optimization --skill convention-rule-of-three

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rule of Three provides a disciplined guideline to refactor duplicated logic after it appears three times, reducing maintenance costs and preventing code rot.

Core Features & Use Cases

  • Detect duplicated logic across modules and prompt refactoring.
  • Promote extracting common preprocessing, validation, or normalization into reusable utilities.
  • Improve consistency, readability, and maintainability across codebases and teams.

Quick Start

Spot repeated patterns after the third occurrence and refactor them into shared utilities.

Frequently Asked Questions about convention-rule-of-three

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

FAQPage Schema
When should I refactor duplicate code to follow the Rule of Three?

You should refactor duplicate code when a specific logic pattern, such as validation or normalization, appears for the third time across your modules. Extracting shared logic into reusable helpers at this stage enforces DRY principles and prevents code rot.

How do I reduce repeated setup and validation logic across multiple modules?

Reduce repeated setup and validation logic by identifying similar patterns across files and extracting them into shared utility helpers after their third occurrence. This process aligns with DRY principles to improve maintainability and readability across teams.

What is the Rule of Three in software engineering refactoring?

The Rule of Three is a disciplined refactoring guideline stating you should extract duplicated logic into reusable utilities only after it has been repeated three times. It balances immediate development speed with long-term code quality and maintainability.

Does the Rule of Three refactoring approach apply to multi-module software projects?

Yes, the Rule of Three refactoring approach specifically targets software projects with multiple modules where similar setup, normalization, or validation logic repeats across different files or teams. It enforces extracting shared logic to ensure consistency.

What is the best way to balance the DRY principle and avoiding premature refactoring?

The best way to balance the DRY principle and avoid premature refactoring is to wait until duplicated code appears three times before extracting it. This approach prevents over-engineering while systematically reducing maintenance costs as the project scales.

Why does delaying refactoring until the third code duplication improve maintainability?

Delaying refactoring until the third code duplication improves maintainability by allowing the correct abstraction pattern to become clear before extraction. This reduces maintenance costs and prevents code rot by ensuring shared helpers are accurately designed.