Skill站外收录 @skilllib/skill-2014279415654461441
engineering-standards
提供面向软件质量提升的工程原则指导,涵盖职责分离、可扩展性设计、类型安全、接口精简和依赖抽象等核心理念,支持在代码审查、架构演进和技术债识别中发现坏味道并给出具体重构路径。
软件开发 AI 技能
Skills.MD
# Engineering Standards
Foundational principles for high-quality software. Use this skill when:
- Reviewing code for quality issues
- Planning architectural changes
- Identifying refactoring opportunities
- Evaluating technical debt
## SOLID Principles
### Single Responsibility (SRP)
A class/module should have one reason to change.
**Detection patterns:**
- Class with 5+ public methods doing unrelated things
- Method longer than 50 lines
- Class name contains "And" or "Manager" with mixed concerns
- File imports from 10+ unrelated modules
**Refactoring:**
- Extract class for each responsibility
- Split into focused modules
- Use composition over inheritance
### Open/Closed (OCP)
Open for extension, closed for modification.
**Detection patterns:**
- Switch/case on type with frequent additions
- if/else chains checking instance types
- Modifying existing code to add new features
**Refactoring:**
- Strategy pattern for varying behaviors
- Plugin architecture for extensions
- Dependency injection for configurability
### Liskov Substitution (LSP)
Subtypes must be substitutable for their base types.
**Detection patterns:**
- Override that throws "not implemented"
- Subclass that ignores parent behavior
- Type checks before calling inherited methods
**Refactoring:**
- Favor composition over inheritance
- Extract interface for true polymorphism
- Use abstract base with required overrides
### Interface Segregation (ISP)
Clients shouldn't depend on methods they don't use.
**Detection patterns:**
- Interface with 10+ methods
- Implementing classes that stub methods as no-ops
- "Fat" interfaces with unrelated method groups
**Refactoring:**
- Split into role-specific interfaces
- Use mixins/traits for optional behaviors
- Compose multiple focused interfaces
### Dependency Inversion (DIP)
Depend on abstractions, not concretions.
**Detection patterns:**
- Direct instantiation of dependencies (`new ConcreteClass()`)
- Hard-coded database/API connections
- Test files creating production instances
**Refactoring:**
- Constructor injection
- Factory pattern for complex creation
- Interface-based dependencies
---
## DRY (Don't Repeat Yourself)
**Detection patterns:**
- Copy-pasted code blocks (3+ occurrences)
- Similar functions with minor variations
- Duplicated validation logic
- Repeated configuration values
**Refactoring:**
- Extract shared function/class
- Parameterize variations
- Create configuration constants
- Use template method pattern
**Exceptions (acceptable duplication):**
- Test code clarity (explicit over DRY)
- Cross-boundary isolation (microservices)
- Performance-critical paths
---
## YAGNI (You Aren't Gonna Need It)
**Detection patterns:**
- Unused parameters "for future use"
- Abstract classes with single implementation
- Configuration options never used
- Speculative generalization
**Guidance:**
- Build for current requirements
- Refactor when needs emerge
- Delete dead code immediately
- Prefer simple over flexible
---
## KISS (Keep It Simple, Stupid)
**Detection patterns:**
- Cyclomatic complexity > 10
- Nested callbacks/promises 4+ deep
- Generic solutions for specific problems
- Framework overkill for simple tasks
**Refactoring:**
- Flatten control flow
- Extract named functions
- Use early returns
- Choose boring technology
---
## Code Smells Quick Reference
| Smell | Symptom | Fix |
|-------|---------|-----|
| Long Method | >50 lines, multiple concerns | Extract method |
| Large Class | >500 lines, many responsibilities | Extract class |
| Feature Envy | Method uses other class more than own | Move method |
| Data Clumps | Same fields appear together | Extract object |
| Primitive Obsession | Strings/ints for domain concepts | Value objects |
| Switch Statements | Type-based switching | Polymorphism |
| Parallel Inheritance | Every subclass needs partner subclass | Merge hierarchies |
| Lazy Class | Class doing too little | Inline class |
| Speculative Generality | Unused abstraction | Remove it |
| Temporary Field | Field only set sometimes | Extract class |
---
## When to Apply
**Always apply:**
- SRP, DRY for production code
- KISS for all code
**Apply with judgment:**
- OCP when extension points are clear
- ISP when interfaces grow beyond 5 methods
- DIP at module boundaries
**Defer:**
- YAGNI violations until pattern emerges 3+ times
See [references/refactoring-catalog.md](references/refactoring-catalog.md) for detailed refactoring techniques.
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「engineering-standards」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次