Files
everything-claude-code/docs/zh-CN/rules/common/patterns.md

35 lines
914 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 常见模式
## 骨架项目
当实现新功能时:
1. 搜索经过实战检验的骨架项目
2. 使用并行代理评估选项:
* 安全性评估
* 可扩展性分析
* 相关性评分
* 实施规划
3. 克隆最佳匹配作为基础
4. 在已验证的结构内迭代
## 设计模式
### 仓库模式
将数据访问封装在一个一致的接口之后:
* 定义标准操作findAll, findById, create, update, delete
* 具体实现处理存储细节数据库、API、文件等
* 业务逻辑依赖于抽象接口,而非存储机制
* 便于轻松切换数据源,并使用模拟对象简化测试
### API 响应格式
对所有 API 响应使用一致的信封格式:
* 包含一个成功/状态指示器
* 包含数据载荷(出错时可为空)
* 包含一个错误消息字段(成功时可为空)
* 为分页响应包含元数据(总数、页码、限制)