返回 Skill 列表
extension
分类: 其它无需 API Key

design-patterns

用于设计解决方案、识别反复出现的问题或使用经过验证的模式改进代码结构。

person作者: piuaibot-stackhubclawhub

Design Patterns

Creational Patterns

  • Singleton — one instance globally (use sparingly, hard to test)
  • Factory Method — delegate instantiation to subclasses
  • Abstract Factory — families of related objects
  • Builder — step-by-step complex object construction
  • Prototype — clone existing objects

Structural Patterns

  • Adapter — incompatible interfaces compatibility
  • Decorator — add behavior without modifying class
  • Facade — simplified interface to complex subsystem
  • Proxy — control access to another object
  • Composite — tree structures, treat individual/group uniformly

Behavioral Patterns

  • Observer — event subscription/notification
  • Strategy — swap algorithms at runtime
  • Command — encapsulate actions as objects
  • Chain of Responsibility — pass request through handler chain
  • Template Method — define skeleton, let subclasses fill in
  • State — change behavior when internal state changes
  • Iterator — traverse collection without exposing internals

Modern Patterns

  • Repository — abstract data layer from business logic
  • Unit of Work — batch DB operations into a transaction
  • CQRS — separate read and write models
  • Saga — distributed transaction management
  • Circuit Breaker — prevent cascading failures

Anti-Patterns to Avoid

  • God Object — class that knows too much
  • Spaghetti Code — no clear structure
  • Golden Hammer — using one pattern for everything
  • Premature Optimization — optimizing before profiling