Token导航 LogoToken导航TokenDH.com
前端设计只读github未标认证来源可访问clear审计通过

single-responsibility-principle单一责任原则

Agent Skill

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。它适合让 Agent 生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构,或定位布局和性能问题。使用时需要结合项目现有设计系统、路由和构建方式,避免只生成孤立片段;涉及页面改动时,应配合本地预览和构建检查确认视觉效果。

总安装

881

周安装

36

GitHub Stars

10

下载量

282
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:single-responsibility-principle(单一责任原则)
来源仓库:https://github.com/yanko-belov/code-craft
仓库路径:skills/single-responsibility-principle
安装命令:
npx skills add https://github.com/yanko-belov/code-craft --skill single-responsibility-principle
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/yanko-belov/code-craft --skill single-responsibility-principle

简介

用于辅助前端页面、组件和样式逻辑的开发与维护。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中生成或审查 React、Vue 等代码。
  • 使用时需结合项目现有设计系统和路由方式,避免生成孤立片段。
  • 涉及页面改动时应配合本地预览和构建检查确认视觉效果。
  • 安装前请核实权限范围和维护状态,避免触发不必要的文件操作。

SKILL.md

Single Responsibility Principle (SRP)

Overview

A class should have only one reason to change.

Every module, class, or function should have responsibility over a single part of functionality. If you can describe what a class does using "AND", it has too many responsibilities.

When to Use

  • Creating any new class, module, or service
  • Adding methods to existing classes
  • Reviewing code that "does multiple things"
  • Feeling pressure to "just add it here"

The Iron Rule

NEVER add functionality that introduces a second reason to change.

No exceptions:

  • Not for "it's faster this way"
  • Not for "it's just one more method"
  • Not for "refactoring would take too long"
  • Not for "my tech lead said so"
  • Not for "it's already in production"

Violating SRP under pressure is still violating SRP.

Detection: The "AND" Test

Describe your class in one sentence. If it contains "AND", split it.

DescriptionVerdict
"Handles user authentication"✅ Single responsibility
"Handles authentication AND sends emails"❌ Two responsibilities
"Manages orders AND processes payments AND tracks inventory"❌ Three responsibilities

Detection: Reasons to Change

List why this class might need to change:

// ❌ BAD: UserManager - 4 reasons to change
class UserManager {
  login() {}           // Auth logic changes
  updateProfile() {}   // Profile requirements change
  sendEmail() {}       // Email provider changes
  trackAnalytics() {}  // Analytics requirements change
}

// ✅ GOOD: Split by responsibility
class AuthService { login() {} }
class ProfileService { updateProfile() {} }
class NotificationService { sendEmail() {} }
class AnalyticsService { track() {} }

Pressure Resistance Protocol

When pressured to violate SRP, follow this:

1. Time Pressure

"Just make it work quickly"

Response: Creating a god class takes the same time as creating focused classes. The "quick" solution creates technical debt that costs 10x more later.

Action: Create separate classes. It's not slower.

2. Sunk Cost Pressure

"The class already exists, just add to it"

Response: Adding to a bloated class makes it worse. The fact that it's already wrong doesn't justify making it more wrong.

Action: Create a new focused class. Refactor the existing one if time permits.

3. Authority Pressure

"My tech lead said put it all in one class"

Response: Respectfully push back with evidence. If overruled, document your concern and comply—but NEVER silently create god classes.

Action:

"I'd recommend splitting this because [specific reason].
If we keep it together, we'll likely need to refactor when [consequence].
Should I proceed with the split, or document this as tech debt?"

4. Scope Creep

"While you're in there, also add X"

Response: New functionality = new class (or existing appropriate class).

Action: "X belongs in its own service. I'll create XService."

Red Flags - STOP and Reconsider

If you notice ANY of these, you're about to violate SRP:

  • Adding a method unrelated to the class's core purpose
  • Class file exceeds 200 lines
  • Class has more than 5-7 public methods
  • You need section comments to navigate the class
  • Multiple developers would edit this class for unrelated features
  • Class name contains "Manager", "Handler", "Processor", "Service" with no specific domain

All of these mean: Split the class.

Refactoring Existing Violations

When you encounter an existing god class:

  1. Don't make it worse - Never add more responsibilities
  2. Extract on touch - When modifying, extract the part you're touching
  3. Document debt - If you can't refactor now, create a ticket
// Found: OrderService with 500 lines handling orders, payments, inventory, emails

// ❌ WRONG: Add shipping logic to OrderService
// ✅ RIGHT: Create ShippingService, note that OrderService needs refactoring

Common Rationalizations (All Invalid)

ExcuseReality
"It's faster to put it in one class"It's not. You type the same code either way.
"Small classes are over-engineering"Small classes are correct engineering.
"It's just one more method"That's how god classes start. Every time.
"We can refactor later"You won't. Tech debt compounds.
"The class is already big"That's a reason to stop, not continue.
"It's related functionality"Related ≠ same responsibility.
"Section comments help navigate"If you need navigation, class is too big.

Quick Reference

SymptomAction
Class does X AND YSplit into XService and YService
Adding unrelated methodCreate new class
File > 200 linesLook for extraction opportunities
Multiple reasons to changeOne class per reason
"Manager/Handler/Processor" nameBe more specific or split

The Bottom Line

One class. One responsibility. One reason to change.

When pressured to violate this: push back, document, or create the right structure anyway.

God classes are never the answer, regardless of time pressure, existing code, or authority demands.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

30.28%
按下载量换算85

Claude Code

21%
按下载量换算59

Antigravity

15.51%
按下载量换算44

windsurf

13.45%
按下载量换算38

github-copilot

8.03%
按下载量换算23

Gemini CLI

3.24%
按下载量换算9

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills