software-patterns
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSoftware Patterns - Unified Knowledge Router
软件模式 - 统一知识路由器
A comprehensive software engineering knowledge base spanning 147 documentation files across 7 focused skills. This router intelligently directs queries to the appropriate underlying skill(s) and orchestrates cross-skill solutions when needed.
这是一个涵盖7个细分技能、包含147份文档的综合性软件工程知识库。该路由器能智能地将查询导向对应的底层技能,并在需要时协调跨技能的解决方案。
When This Skill Activates
本技能的激活场景
This skill automatically activates when you:
- Need to choose between design patterns or algorithms
- Design system architecture or data models
- Discuss code quality, refactoring, or best practices
- Select data structures for specific requirements
- Design distributed systems or databases
- Model complex business domains
- Apply fundamental programming concepts
当你有以下需求时,本技能会自动激活:
- 需要在设计模式或算法之间做选择
- 设计系统架构或数据模型
- 讨论代码质量、重构或最佳实践
- 根据特定需求选择数据结构
- 设计分布式系统或数据库
- 建模复杂业务领域
- 应用基础编程概念
Quick Reference: What Each Skill Covers
快速参考:各技能覆盖范围
| Skill | Files | Coverage | Use For |
|---|---|---|---|
| gof-patterns | 25 | 23 GoF design patterns + selection guides | Object creation, composition, behavior |
| clrs-algorithms | 40 | Data structures & algorithms | Performance optimization, algorithm selection |
| clean-code | 14 | SOLID principles + 8 practices | Code quality, refactoring, maintainability |
| ddia | 21 | Distributed systems concepts | Scalability, consistency, availability |
| pragmatic-programmer | 19 | 7 principles + 11 practices | Software craftsmanship, debugging, tooling |
| ddd | 15 | 4 strategic + 5 tactical patterns | Domain modeling, bounded contexts |
| sicp | 13 | 12 fundamental CS concepts | Abstraction, recursion, interpreters |
Total: 147 documentation files
| 技能 | 文档数 | 覆盖内容 | 适用场景 |
|---|---|---|---|
| gof-patterns | 25 | 23种GoF设计模式 + 选型指南 | 对象创建、组合、行为设计 |
| clrs-algorithms | 40 | 数据结构与算法 | 性能优化、算法选型 |
| clean-code | 14 | SOLID原则 + 8项实践 | 代码质量、重构、可维护性 |
| ddia | 21 | 分布式系统概念 | 可扩展性、一致性、可用性 |
| pragmatic-programmer | 19 | 7项原则 + 11项实践 | 编程技艺、调试、工具使用 |
| ddd | 15 | 4种战略模式 + 5种战术模式 | 领域建模、限界上下文 |
| sicp | 13 | 12项计算机科学基础概念 | 抽象、递归、解释器 |
总计:147份文档
Query Commands
查询命令
Pattern Queries
模式查询
/pattern <problem>Find design patterns for a specific problem.
Examples:
- → Factory Method
/pattern create objects without knowing exact type - → Decorator
/pattern add behavior dynamically - → Observer
/pattern notify multiple objects of changes - → Facade
/pattern simplify complex subsystem
Routes to: skill with pattern-selection.md
gof-patterns/pattern <问题>为特定问题匹配设计模式。
示例:
- → 工厂方法模式
/pattern create objects without knowing exact type - → 装饰器模式
/pattern add behavior dynamically - → 观察者模式
/pattern notify multiple objects of changes - → 外观模式
/pattern simplify complex subsystem
路由至: 技能的 pattern-selection.md
gof-patternsData Structure Queries
数据结构查询
/ds <requirement>Find data structures for specific requirements.
Examples:
- → Hash Table
/ds fast lookup by key - → Tree Set or Heap
/ds maintain sorted order - → Deque
/ds fast insert/delete at ends - → Binary Heap
/ds priority queue
Routes to: skill with data-structure-selection.md
clrs-algorithms/ds <需求>为特定需求匹配数据结构。
示例:
- → 哈希表
/ds fast lookup by key - → 树集或堆
/ds maintain sorted order - → 双端队列
/ds fast insert/delete at ends - → 二叉堆
/ds priority queue
路由至: 技能的 data-structure-selection.md
clrs-algorithmsArchitecture Queries
架构查询
/architecture <scenario>Get multi-skill solution stacks combining patterns, data structures, and distributed systems concepts.
Examples:
- → State pattern + Command + Observer + distributed transactions
/architecture e-commerce checkout - → Sorted Set + Redis + Pub/Sub
/architecture real-time leaderboard - → Abstract Factory + Bounded Contexts + Partitioning
/architecture multi-tenant SaaS
Routes to: Orchestrates across , , , and
gof-patternsclrs-algorithmsddiaddd/architecture <场景>获取结合模式、数据结构和分布式系统概念的跨技能解决方案栈。
示例:
- → 状态模式 + 命令模式 + 观察者模式 + 分布式事务
/architecture e-commerce checkout - → 有序集合 + Redis + 发布/订阅
/architecture real-time leaderboard - → 抽象工厂模式 + 限界上下文 + 分区策略
/architecture multi-tenant SaaS
路由至: 协调 、、 和 技能
gof-patternsclrs-algorithmsddiadddImplementation Queries
实现查询
/implement <pattern> [language]Generate implementation code for a pattern in a specific language.
Examples:
/implement factory method typescript/implement observer python/implement heap java
Routes to: Appropriate skill with language-specific translation
/implement <pattern> [language]生成特定语言下的模式实现代码。
示例:
/implement factory method typescript/implement observer python/implement heap java
路由至: 对应技能的语言专属文档
Comparison Queries
对比查询
/compare <a> vs <b>Trade-off analysis between two approaches.
Examples:
/compare factory method vs abstract factory/compare array vs linked list/compare postgres vs mongodb/compare event sourcing vs crud
Routes to: Relevant skill(s) with comparison tables
/compare <a> vs <b>两种方案的权衡分析。
示例:
/compare factory method vs abstract factory/compare array vs linked list/compare postgres vs mongodb/compare event sourcing vs crud
路由至: 相关技能的对比表格文档
How the Router Works
路由器工作原理
1. Query Parsing
1. 查询解析
The router analyzes queries for problem indicators:
yaml
patterns:
- "create", "instantiate", "build" → Creational patterns
- "structure", "compose", "organize" → Structural patterns
- "behavior", "algorithm", "interact" → Behavioral patterns
data_structures:
- "fast lookup", "search", "find" → Hash or Tree
- "sorted", "ordered" → Tree or Heap
- "insert", "delete", "add", "remove" → List or Tree
- "queue", "stack", "priority" → Specialized structures
distributed_systems:
- "scale", "partition", "shard" → ddia/partitioning
- "replicate", "consistency" → ddia/replication
- "distributed", "consensus" → ddia/consensus
domain_modeling:
- "entity", "value object", "aggregate" → ddd/tactical
- "bounded context", "ubiquitous language" → ddd/strategic路由器会分析查询中的问题关键词:
yaml
patterns:
- "create", "instantiate", "build" → 创建型模式
- "structure", "compose", "organize" → 结构型模式
- "behavior", "algorithm", "interact" → 行为型模式
data_structures:
- "fast lookup", "search", "find" → 哈希或树结构
- "sorted", "ordered" → 树或堆
- "insert", "delete", "add", "remove" → 列表或树
- "queue", "stack", "priority" → 专用结构
distributed_systems:
- "scale", "partition", "shard" → ddia/partitioning
- "replicate", "consistency" → ddia/replication
- "distributed", "consensus" → ddia/consensus
domain_modeling:
- "entity", "value object", "aggregate" → ddd/tactical
- "bounded context", "ubiquitous language" → ddd/strategic2. Skill Routing
2. 技能路由
Based on query type, routes to one or more skills:
| Query Type | Primary Skill | Supporting Skills |
|---|---|---|
| Design pattern | | |
| Data structure | | |
| Code quality | | |
| Distributed systems | | |
| Domain modeling | | |
| Fundamentals | | |
| Architecture | ALL | Orchestrated solution |
根据查询类型,路由至一个或多个技能:
| 查询类型 | 主技能 | 辅助技能 |
|---|---|---|
| 设计模式 | | |
| 数据结构 | | |
| 代码质量 | | |
| 分布式系统 | | |
| 领域建模 | | |
| 基础概念 | | |
| 架构设计 | 全部技能 | 协调式解决方案 |
3. Cross-Skill Orchestration
3. 跨技能协调
For complex problems, the router orchestrates multiple skills:
Example: "Design a caching layer for a distributed system"
1. clrs-algorithms → LRU cache data structure (Hash Table + Doubly Linked List)
2. gof-patterns → Proxy pattern (control access), Flyweight (share state)
3. ddia → Replication strategies, consistency models
4. clean-code → Interface design, SOLID principlesExample: "Build an e-commerce order processing system"
1. ddd → Order aggregate, bounded contexts (order, payment, shipping)
2. gof-patterns → State (order states), Command (payment actions), Observer (notifications)
3. clrs-algorithms → Priority Queue (order processing), Hash Table (inventory lookup)
4. ddia → Event sourcing, CQRS, distributed transactions
5. clean-code → SRP (one class per concern), DIP (depend on abstractions)针对复杂问题,路由器会协调多个技能:
示例:"为分布式系统设计缓存层"
1. clrs-algorithms → LRU缓存数据结构(哈希表 + 双向链表)
2. gof-patterns → 代理模式(访问控制)、享元模式(状态共享)
3. ddia → 复制策略、一致性模型
4. clean-code → 接口设计、SOLID原则示例:"构建电商订单处理系统"
1. ddd → 订单聚合、限界上下文(订单、支付、物流)
2. gof-patterns → 状态模式(订单状态)、命令模式(支付操作)、观察者模式(通知)
3. clrs-algorithms → 优先队列(订单处理)、哈希表(库存查询)
4. ddia → 事件溯源、CQRS、分布式事务
5. clean-code → SRP(单一职责)、DIP(依赖抽象)Auto-Trigger Rules
自动触发规则
This skill activates automatically when queries contain these indicators:
当查询包含以下关键词时,本技能自动激活:
Pattern/Design Indicators
模式/设计关键词
- "which pattern", "design pattern", "should I use"
- "factory", "singleton", "observer", "decorator", "adapter"
- "create objects", "add behavior", "simplify interface"
- "which pattern", "design pattern", "should I use"
- "factory", "singleton", "observer", "decorator", "adapter"
- "create objects", "add behavior", "simplify interface"
Data Structure Indicators
数据结构关键词
- "which data structure", "fast lookup", "sorted order"
- "array", "list", "tree", "hash", "graph", "heap"
- "O(1)", "O(log n)", "complexity", "time/space"
- "which data structure", "fast lookup", "sorted order"
- "array", "list", "tree", "hash", "graph", "heap"
- "O(1)", "O(log n)", "complexity", "time/space"
Architecture Indicators
架构关键词
- "design", "architecture", "how should I structure"
- "scalable", "distributed", "high availability"
- "microservices", "event-driven", "domain model"
- "design", "architecture", "how should I structure"
- "scalable", "distributed", "high availability"
- "microservices", "event-driven", "domain model"
Code Quality Indicators
代码质量关键词
- "refactor", "code smell", "clean up", "improve"
- "SOLID", "DRY", "naming", "function size"
- "test", "maintainable", "readable"
- "refactor", "code smell", "clean up", "improve"
- "SOLID", "DRY", "naming", "function size"
- "test", "maintainable", "readable"
Skill Coverage Details
技能覆盖详情
GoF Patterns (gof-patterns)
GoF Patterns (gof-patterns)
Creational (5 patterns):
- Abstract Factory, Builder, Factory Method, Prototype, Singleton
Structural (7 patterns):
- Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy
Behavioral (11 patterns):
- Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor
Decision Guides:
- pattern-selection.md - Comprehensive selection guide
- Problem → Pattern mapping
- Common combinations
- Anti-patterns to avoid
创建型(5种):
- 抽象工厂、建造者、工厂方法、原型、单例
结构型(7种):
- 适配器、桥接、组合、装饰器、外观、享元、代理
行为型(11种):
- 责任链、命令、解释器、迭代器、中介者、备忘录、观察者、状态、策略、模板方法、访问者
决策指南:
- pattern-selection.md - 综合选型指南
- 问题→模式映射
- 常见组合
- 需避免的反模式
CLRS Algorithms (clrs-algorithms)
CLRS Algorithms (clrs-algorithms)
Linear Structures (6):
- Array, Dynamic Array, Linked List, Stack, Queue, Deque
Trees (12):
- Binary Tree, BST, AVL, Red-Black, B-Tree, Trie, Heap, Splay Tree, Treap, Interval Tree, Order-Statistic Tree, K-D Tree
Hash-Based (3):
- Hash Table, Hash Set, Bloom Filter
Graphs (5):
- Adjacency List/Matrix, Network Flow, Strongly Connected Components, plus algorithms (BFS, DFS, Dijkstra, etc.)
Advanced (7):
- Skip List, Disjoint Set, Segment Tree, Fenwick Tree, Fibonacci Heap, Binomial Heap, van Emde Boas Tree
Strings (3):
- String Algorithms (KMP, Rabin-Karp), Suffix Array, Suffix Tree
Algorithms:
- Sorting (QuickSort, MergeSort, HeapSort, RadixSort)
Decision Guides:
- data-structure-selection.md - "I need fast..." scenarios
- complexity-cheat-sheet.md - Big-O reference
线性结构(6种):
- 数组、动态数组、链表、栈、队列、双端队列
树结构(12种):
- 二叉树、BST、AVL、红黑树、B树、前缀树、堆、伸展树、树堆、区间树、顺序统计树、K-D树
哈希结构(3种):
- 哈希表、哈希集合、布隆过滤器
图结构(5种):
- 邻接表/矩阵、网络流、强连通分量,以及算法(BFS、DFS、Dijkstra等)
高级结构(7种):
- 跳表、并查集、线段树、 Fenwick树、斐波那契堆、二项堆、van Emde Boas树
字符串(3种):
- 字符串算法(KMP、Rabin-Karp)、后缀数组、后缀树
算法:
- 排序(快速排序、归并排序、堆排序、基数排序)
决策指南:
- data-structure-selection.md - "我需要快速..."场景选型
- complexity-cheat-sheet.md - 时间复杂度速查表
Clean Code (clean-code)
Clean Code (clean-code)
SOLID Principles (5):
- Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion
Practices (8):
- Meaningful Names, Functions, Comments, Formatting, Error Handling, Unit Testing, Code Smells, Boy Scout Rule
SOLID原则(5项):
- 单一职责、开闭、里氏替换、接口隔离、依赖倒置
实践(8项):
- 有意义的命名、函数设计、注释、代码格式化、错误处理、单元测试、代码坏味、童子军规则
DDIA (ddia)
DDIA (ddia)
Data Models (3):
- Relational, Document, Graph
Storage (3):
- B-Trees, LSM-Trees, Column Storage
Replication (3):
- Leader-Follower, Multi-Leader, Leaderless
Partitioning (2):
- Strategies, Rebalancing
Transactions (3):
- ACID, Isolation Levels, Distributed Transactions
Consistency (2):
- Models, Linearizability
Consensus (1):
- Algorithms (Paxos, Raft)
Processing (3):
- Batch, Stream, Event Sourcing/CQRS
数据模型(3种):
- 关系型、文档型、图型
存储引擎(3种):
- B树、LSM树、列存储
复制策略(3种):
- 主从复制、多主复制、无主复制
分区策略(2种):
- 分区方案、重平衡
事务(3种):
- ACID、隔离级别、分布式事务
一致性(2种):
- 一致性模型、线性一致性
共识算法(1种):
- Paxos、Raft等算法
数据处理(3种):
- 批处理、流处理、事件溯源/CQRS
Pragmatic Programmer (pragmatic-programmer)
Pragmatic Programmer (pragmatic-programmer)
Principles (7):
- DRY, Orthogonality, Reversibility, Tracer Bullets, Prototypes, Domain Languages, Estimating
Practices (11):
- Plain Text, Shell Games, Debugging, Text Manipulation, Code Generators, Design by Contract, Assertive Programming, Decoupling, Refactoring, Testing, Automation
原则(7项):
- DRY、正交性、可逆性、 tracer bullets、原型、领域语言、估算
实践(11项):
- 纯文本、Shell脚本、调试、文本处理、代码生成器、契约式设计、断言式编程、解耦、重构、测试、自动化
Domain-Driven Design (ddd)
Domain-Driven Design (ddd)
Strategic Patterns (4):
- Ubiquitous Language, Bounded Contexts, Context Mapping, Anti-Corruption Layer
Tactical Patterns (5):
- Entities, Value Objects, Aggregates, Domain Services, Domain Events
Supporting Patterns (3):
- Repositories, Factories, Specifications
Practices (2):
- Event Storming, Model Exploration
战略模式(4种):
- 通用语言、限界上下文、上下文映射、防腐层
战术模式(5种):
- 实体、值对象、聚合、领域服务、领域事件
支持模式(3种):
- 仓库、工厂、规格
实践(2项):
- 事件风暴、模型探索
SICP (sicp)
SICP (sicp)
Procedures (3):
- Abstraction, Higher-Order Functions, Recursion Patterns (linear, tail, tree, mutual)
Data (3):
- Data Abstraction, Hierarchical Data, Symbolic Data
Modularity (3):
- Assignment and State, Environment Model, Streams
Metalinguistic (3):
- Interpreters, Lazy Evaluation, Register Machines
过程(3项):
- 抽象、高阶函数、递归模式(线性、尾递归、树递归、互递归)
数据(3项):
- 数据抽象、分层数据、符号数据
模块化(3项):
- 赋值与状态、环境模型、流
元语言(3项):
- 解释器、惰性求值、寄存器机
Cross-Skill Solution Stacks
跨技能解决方案栈
Common Architecture Patterns
常见架构模式
1. The Cache Stack
1. 缓存栈
Pattern: Caching layer with eviction policy
Skills Used:
- clrs-algorithms: Hash Table + Doubly Linked List (LRU)
- gof-patterns: Proxy (control access), Flyweight (share state)
- ddia: Replication (distributed cache), Consistency (cache coherence)
- clean-code: SRP (separate concerns), DIP (interface-based)
Implementation Guide:
1. Use Hash Table for O(1) key lookup
2. Use Doubly Linked List for O(1) LRU eviction
3. Apply Proxy pattern to control access and logging
4. Apply Flyweight to share immutable state
5. Consider replication strategy for distributed scenarios模式:带有淘汰策略的缓存层
使用技能:
- clrs-algorithms: 哈希表 + 双向链表(LRU)
- gof-patterns: 代理模式(访问控制)、享元模式(状态共享)
- ddia: 复制(分布式缓存)、一致性(缓存一致性)
- clean-code: SRP(分离关注点)、DIP(基于接口)
实现指南:
1. 使用哈希表实现O(1)键查询
2. 使用双向链表实现O(1)LRU淘汰
3. 应用代理模式控制访问和日志
4. 应用享元模式共享不可变状态
5. 分布式场景下考虑复制策略2. The Event Pipeline
2. 事件流水线
Pattern: Event-driven system with processing pipeline
Skills Used:
- gof-patterns: Observer (event notification), Command (encapsulate actions)
- clrs-algorithms: Queue (FIFO processing), Priority Queue (prioritized events)
- ddia: Stream Processing (Kafka/Flink), Event Sourcing
- ddd: Domain Events, Aggregates (event producers)
- clean-code: SRP (one handler per event type)
Implementation Guide:
1. Use Observer for event subscription
2. Use Queue or Priority Queue for event buffer
3. Use Command pattern for event handlers
4. Apply Event Sourcing for audit trail
5. Define Domain Events in Ubiquitous Language模式:带有处理流水线的事件驱动系统
使用技能:
- gof-patterns: 观察者模式(事件通知)、命令模式(封装操作)
- clrs-algorithms: 队列(FIFO处理)、优先队列(事件优先级)
- ddia: 流处理(Kafka/Flink)、事件溯源
- ddd: 领域事件、聚合(事件生产者)
- clean-code: SRP(每种事件类型对应一个处理器)
实现指南:
1. 使用观察者模式实现事件订阅
2. 使用队列或优先队列作为事件缓冲区
3. 使用命令模式实现事件处理器
4. 应用事件溯源实现审计追踪
5. 用通用语言定义领域事件3. The Multi-Tenant SaaS
3. 多租户SaaS
Pattern: Isolated tenants with shared infrastructure
Skills Used:
- ddd: Bounded Contexts (per tenant or shared), Context Mapping
- gof-patterns: Abstract Factory (tenant-specific objects), Strategy (tenant policies)
- clrs-algorithms: Hash Table (tenant lookup), B-Tree (tenant data indexing)
- ddia: Partitioning (tenant sharding), Isolation Levels
- clean-code: OCP (extend without modifying), ISP (tenant-specific interfaces)
Implementation Guide:
1. Define Bounded Context boundaries (shared kernel vs separate)
2. Use Abstract Factory for tenant-specific object creation
3. Use Strategy for tenant-specific policies (pricing, limits)
4. Partition data by tenant ID for isolation
5. Choose appropriate isolation level (row-level, schema-level, database-level)模式:隔离租户的共享基础设施
使用技能:
- ddd: 限界上下文(按租户或共享)、上下文映射
- gof-patterns: 抽象工厂模式(租户专属对象)、策略模式(租户策略)
- clrs-algorithms: 哈希表(租户查询)、B树(租户数据索引)
- ddia: 分区(租户分片)、隔离级别
- clean-code: OCP(扩展无需修改)、ISP(租户专属接口)
实现指南:
1. 定义限界上下文边界(共享内核 vs 独立上下文)
2. 使用抽象工厂创建租户专属对象
3. 使用策略模式实现租户专属策略(定价、限制)
4. 按租户ID分区实现数据隔离
5. 选择合适的隔离级别(行级、 schema级、数据库级)4. The E-Commerce Order System
4. 电商订单系统
Pattern: Order processing with inventory, payment, shipping
Skills Used:
- ddd: Aggregates (Order, Inventory, Payment), Bounded Contexts
- gof-patterns: State (order lifecycle), Command (payment operations), Observer (notifications)
- clrs-algorithms: Priority Queue (order processing), Hash Table (inventory lookup)
- ddia: Distributed Transactions (Saga pattern), Event Sourcing
- clean-code: SRP (separate concerns), DIP (depend on repositories)
Implementation Guide:
1. Define Order Aggregate with invariants
2. Use State pattern for order states (cart → payment → processing → shipped)
3. Use Command for payment operations (process, refund, cancel)
4. Use Observer for notifications (customer, warehouse, shipping)
5. Apply Saga pattern for distributed transaction coordination
6. Use Event Sourcing for order history and replay模式:包含库存、支付、物流的订单处理系统
使用技能:
- ddd: 聚合(订单、库存、支付)、限界上下文
- gof-patterns: 状态模式(订单生命周期)、命令模式(支付操作)、观察者模式(通知)
- clrs-algorithms: 优先队列(订单处理)、哈希表(库存查询)
- ddia: 分布式事务(Saga模式)、事件溯源
- clean-code: SRP(分离关注点)、DIP(依赖仓库)
实现指南:
1. 定义带有不变量的订单聚合
2. 使用状态模式管理订单状态(购物车→支付→处理→发货)
3. 使用命令模式封装支付操作(处理、退款、取消)
4. 使用观察者模式实现通知(客户、仓库、物流)
5. 应用Saga模式协调分布式事务
6. 使用事件溯源实现订单历史和重放5. The Real-Time Leaderboard
5. 实时排行榜
Pattern: Sorted rankings with fast updates
Skills Used:
- clrs-algorithms: Red-Black Tree or Skip List (sorted rankings), Hash Table (user lookup)
- gof-patterns: Observer (rank change notifications), Memento (snapshot rankings)
- ddia: Replication (read scaling), Partitioning (range-based)
- clean-code: Functions (small, focused), DRY (ranking logic)
Implementation Guide:
1. Use Sorted Set (Red-Black Tree) for O(log n) insert/delete/rank
2. Use Hash Table for O(1) user score lookup
3. Apply Observer for real-time rank change notifications
4. Use Read Replicas for scaling leaderboard queries
5. Partition by rank ranges for very large leaderboards模式:支持快速更新的排序排名系统
使用技能:
- clrs-algorithms: 红黑树或跳表(排序排名)、哈希表(用户查询)
- gof-patterns: 观察者模式(排名变化通知)、备忘录模式(排名快照)
- ddia: 复制(读扩展)、分区(范围分区)
- clean-code: 小而聚焦的函数、DRY(排名逻辑复用)
实现指南:
1. 使用有序集合(红黑树)实现O(log n)的插入/删除/排名查询
2. 使用哈希表实现O(1)的用户分数查询
3. 应用观察者模式实现实时排名变化通知
4. 使用只读副本扩展排行榜查询能力
5. 超大规模排行榜按排名范围分区Usage Examples
使用示例
Example 1: Pattern Selection
示例1:模式选型
Query: "I need to create objects without specifying their concrete classes"
Router Response:
Primary Match: Creational Patterns (gof-patterns)
Recommendation: Factory Method Pattern
Routing to: gof-patterns/gof-creational/factory-method.md
Additional Considerations:
- If creating families of related objects → Abstract Factory
- If construction is complex → Builder
- See: gof-patterns/pattern-selection.md for decision tree查询: "I need to create objects without specifying their concrete classes"
路由器响应:
Primary Match: Creational Patterns (gof-patterns)
Recommendation: Factory Method Pattern
Routing to: gof-patterns/gof-creational/factory-method.md
Additional Considerations:
- If creating families of related objects → Abstract Factory
- If construction is complex → Builder
- See: gof-patterns/pattern-selection.md for decision treeExample 2: Data Structure Selection
示例2:数据结构选型
Query: "What's the best data structure for fast lookup and maintaining sorted order?"
Router Response:
Primary Match: Data Structure Selection (clrs-algorithms)
Recommendation: Tree Map (Red-Black Tree or AVL Tree)
Comparison:
- Hash Table: O(1) lookup, NO sorted order
- Tree Map: O(log n) lookup, YES sorted order ✓
- Sorted Array: O(log n) search, O(n) insert ✗
Routing to: clrs-algorithms/data-structures/trees/red-black-tree.md
See also: clrs-algorithms/data-structure-selection.md查询: "What's the best data structure for fast lookup and maintaining sorted order?"
路由器响应:
Primary Match: Data Structure Selection (clrs-algorithms)
Recommendation: Tree Map (Red-Black Tree or AVL Tree)
Comparison:
- Hash Table: O(1) lookup, NO sorted order
- Tree Map: O(log n) lookup, YES sorted order ✓
- Sorted Array: O(log n) search, O(n) insert ✗
Routing to: clrs-algorithms/data-structures/trees/red-black-tree.md
See also: clrs-algorithms/data-structure-selection.mdExample 3: Architecture Design
示例3:架构设计
Query: "Design a notification system that supports email, SMS, and push notifications"
Router Response:
Multi-Skill Solution:
1. Pattern Selection (gof-patterns):
- Observer Pattern: Subscribe to events
- Strategy Pattern: Switch between notification methods
- Command Pattern: Queue notification actions
2. Data Structures (clrs-algorithms):
- Priority Queue: Prioritize urgent notifications
- Hash Table: User preference lookup
3. Distributed Systems (ddia):
- Queue (Kafka/RabbitMQ): Async processing
- Retry mechanisms: Handle failures
4. Code Quality (clean-code):
- SRP: One class per notification channel
- OCP: Add new channels without modifying existing
Implementation Stack:
Observer → Command → Priority Queue → Strategy → DIP查询: "Design a notification system that supports email, SMS, and push notifications"
路由器响应:
Multi-Skill Solution:
1. Pattern Selection (gof-patterns):
- Observer Pattern: Subscribe to events
- Strategy Pattern: Switch between notification methods
- Command Pattern: Queue notification actions
2. Data Structures (clrs-algorithms):
- Priority Queue: Prioritize urgent notifications
- Hash Table: User preference lookup
3. Distributed Systems (ddia):
- Queue (Kafka/RabbitMQ): Async processing
- Retry mechanisms: Handle failures
4. Code Quality (clean-code):
- SRP: One class per notification channel
- OCP: Add new channels without modifying existing
Implementation Stack:
Observer → Command → Priority Queue → Strategy → DIPExample 4: Code Quality Review
示例4:代码质量评审
Query: "This function is 200 lines long and does too many things. How do I improve it?"
Router Response:
Primary Match: Code Quality (clean-code)
Violations Detected:
1. Single Responsibility Principle (SRP) - function does too many things
2. Function size - should be 5-20 lines
Refactoring Steps:
1. Extract methods for each responsibility (clean-code/practices/functions.md)
2. Apply SRP (clean-code/solid/single-responsibility.md)
3. Use meaningful names (clean-code/practices/meaningful-names.md)
Supporting Guidance:
- pragmatic-programmer/practices/refactoring.md: When and how to refactor
- gof-patterns: Consider Template Method or Strategy if algorithm varies
Tools:
- Extract Method refactoring
- Compose Method pattern
- Replace Temp with Query查询: "This function is 200 lines long and does too many things. How do I improve it?"
路由器响应:
Primary Match: Code Quality (clean-code)
Violations Detected:
1. Single Responsibility Principle (SRP) - function does too many things
2. Function size - should be 5-20 lines
Refactoring Steps:
1. Extract methods for each responsibility (clean-code/practices/functions.md)
2. Apply SRP (clean-code/solid/single-responsibility.md)
3. Use meaningful names (clean-code/practices/meaningful-names.md)
Supporting Guidance:
- pragmatic-programmer/practices/refactoring.md: When and how to refactor
- gof-patterns: Consider Template Method or Strategy if algorithm varies
Tools:
- Extract Method refactoring
- Compose Method pattern
- Replace Temp with QueryLanguage Translation Notes
语言适配说明
All examples use language-agnostic pseudocode with these conventions:
- for type definitions
class - for methods/functions
function - for method calls on objects
-> - for comments
// - Type hints shown as
name: Type
所有示例使用与语言无关的伪代码,遵循以下约定:
- 用于类型定义
class - 用于方法/函数
function - 用于对象方法调用
-> - 用于注释
// - 类型提示格式为
name: Type
Translation Guide
语言适配指南
| Language | Class | Method | Call | Comment | Types |
|---|---|---|---|---|---|
| PHP | | | | | Docblocks or PHP 8+ |
| JavaScript | | | | | JSDoc or TypeScript |
| TypeScript | | method / arrow | | | Native types |
| Python | | | | | Type hints |
| Java | | method | | | Native types |
| C# | | method | | | Native types |
| Go | | | | | Native types |
| Rust | | | | | Native types |
| 语言 | 类定义 | 方法定义 | 调用方式 | 注释 | 类型 |
|---|---|---|---|---|---|
| PHP | | | | | 文档块或PHP 8+类型 |
| JavaScript | | | | | JSDoc或TypeScript |
| TypeScript | | 方法 / 箭头函数 | | | 原生类型 |
| Python | | | | | 类型提示 |
| Java | | 方法 | | | 原生类型 |
| C# | | 方法 | | | 原生类型 |
| Go | | | | | 原生类型 |
| Rust | | | | | 原生类型 |
Advanced Usage
高级用法
Combining Multiple Skills
多技能组合查询
For complex problems, explicitly request multi-skill analysis:
"I need a comprehensive solution for [problem] covering patterns, data structures, and distributed systems"The router will orchestrate across all relevant skills and provide:
- Pattern recommendations (gof-patterns)
- Data structure choices (clrs-algorithms)
- Scalability considerations (ddia)
- Domain modeling (ddd if applicable)
- Code quality guidelines (clean-code)
- Implementation best practices (pragmatic-programmer)
针对复杂问题,可明确请求多技能分析:
"I need a comprehensive solution for [problem] covering patterns, data structures, and distributed systems"路由器会协调所有相关技能,并提供:
- 模式推荐(gof-patterns)
- 数据结构选型(clrs-algorithms)
- 可扩展性考量(ddia)
- 领域建模建议(ddd 适用时)
- 代码质量指南(clean-code)
- 实现最佳实践(pragmatic-programmer)
Deep Dives
深度探索
Request detailed documentation from specific skills:
"Show me the full Observer pattern documentation"
→ Routes to: gof-patterns/gof-behavioral/observer.md
"Explain Red-Black Tree implementation with examples"
→ Routes to: clrs-algorithms/data-structures/trees/red-black-tree.md
"What are all SOLID principles?"
→ Routes to: clean-code/solid/ (all 5 principles)请求特定技能的详细文档:
"Show me the full Observer pattern documentation"
→ 路由至:gof-patterns/gof-behavioral/observer.md
"Explain Red-Black Tree implementation with examples"
→ 路由至:clrs-algorithms/data-structures/trees/red-black-tree.md
"What are all SOLID principles?"
→ 路由至:clean-code/solid/(全部5项原则)Comparison Queries
对比查询
Request trade-off analysis:
"/compare singleton vs dependency injection"
→ Multi-skill analysis from gof-patterns + clean-code
"/compare b-tree vs lsm-tree"
→ Multi-skill analysis from clrs-algorithms + ddia
"/compare entity vs value object"
→ Analysis from ddd/tactical/请求权衡分析:
"/compare singleton vs dependency injection"
→ 来自 gof-patterns + clean-code 的多技能分析
"/compare b-tree vs lsm-tree"
→ 来自 clrs-algorithms + ddia 的多技能分析
"/compare entity vs value object"
→ 来自 ddd/tactical/ 的分析Tips for Effective Use
高效使用技巧
1. Start with Problem, Not Solution
1. 从问题出发,而非解决方案
❌ "Show me the Singleton pattern"
✅ "I need exactly one instance of a configuration manager"
The router will recommend the right pattern and warn about potential issues.
❌ "Show me the Singleton pattern"
✅ "I need exactly one instance of a configuration manager"
路由器会推荐合适的模式,并提示潜在问题。
2. Provide Context
2. 提供上下文信息
❌ "Which data structure should I use?"
✅ "I need fast lookup by key and sorted iteration over 10,000 items"
Context enables better routing and recommendations.
❌ "Which data structure should I use?"
✅ "I need fast lookup by key and sorted iteration over 10,000 items"
上下文信息能提升路由准确性和推荐质量。
3. Ask About Trade-offs
3. 询问权衡方案
✅ "What are the trade-offs between Factory Method and Abstract Factory?"
✅ "When should I use Array vs Linked List?"
✅ "Compare event sourcing vs traditional CRUD"
Trade-off queries trigger comparison mode with tables and decision guides.
✅ "What are the trade-offs between Factory Method and Abstract Factory?"
✅ "When should I use Array vs Linked List?"
✅ "Compare event sourcing vs traditional CRUD"
权衡查询会触发带有表格和决策指南的对比模式。
4. Request Implementation Guidance
4. 请求实现指导
✅ "How do I implement LRU cache in TypeScript?"
✅ "Show me Observer pattern in Python"
✅ "Implement Repository pattern in PHP"
Includes language-specific code generation with best practices.
✅ "How do I implement LRU cache in TypeScript?"
✅ "Show me Observer pattern in Python"
✅ "Implement Repository pattern in PHP"
包含符合最佳实践的语言专属代码生成。
5. Explore Related Concepts
5. 探索相关概念
After getting a recommendation, ask:
- "What patterns work well with [pattern]?"
- "What are common combinations with [data structure]?"
- "How does [concept] relate to [other concept]?"
获取推荐后,可进一步询问:
- "What patterns work well with [pattern]?"
- "What are common combinations with [data structure]?"
- "How does [concept] relate to [other concept]?"
Contributing
贡献指南
To add new patterns, algorithms, or concepts to any skill:
- Follow the established format in existing documentation
- Include definition, when to use, implementation, examples, trade-offs
- Update the relevant SKILL.md quick reference tables
- Add decision guide entries if applicable
如需向任一技能添加新模式、算法或概念:
- 遵循现有文档的格式规范
- 包含定义、适用场景、实现、示例、权衡
- 更新对应SKILL.md的快速参考表格
- 适用时添加决策指南条目
Acknowledgments
致谢
This unified knowledge base is built on the shoulders of giants:
- Gang of Four (Gamma, Helm, Johnson, Vlissides): Design Patterns
- CLRS (Cormen, Leiserson, Rivest, Stein): Introduction to Algorithms
- Robert C. Martin (Uncle Bob): Clean Code
- Martin Kleppmann: Designing Data-Intensive Applications
- Eric Evans: Domain-Driven Design
- Andrew Hunt & David Thomas: The Pragmatic Programmer
- Harold Abelson & Gerald Jay Sussman: Structure and Interpretation of Computer Programs
Made with Claude Code
Total: 147 documentation files across 7 focused skills
这个统一知识库站在巨人的肩膀上构建:
- Gang of Four(Gamma, Helm, Johnson, Vlissides):《设计模式》
- CLRS(Cormen, Leiserson, Rivest, Stein):《算法导论》
- Robert C. Martin(Uncle Bob):《代码整洁之道》
- Martin Kleppmann:《设计数据密集型应用》
- Eric Evans:《领域驱动设计》
- Andrew Hunt & David Thomas:《程序员修炼之道》
- Harold Abelson & Gerald Jay Sussman:《计算机程序的构造和解释》
Made with Claude Code
Total: 147 documentation files across 7 focused skills