360 Secure SkillHub
360 安全技能中心

design-patterns

提供软件设计模式的知识参考,列举创建型、结构型、行为型、现代模式及常见反模式,用于方案架构、识别重复问题和改进代码结构;内容为纯文本清单,不含代码示例或外部工具调用。

piuaibot-stack
piuaibot-stack
热度 37.24
最近更新 2026-05-11 17:46:05
分类:知识依赖:纯提示词应用场景:概念解释

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add design-patterns
Metadata
name
design-patterns
description
Use when architecting solutions, identifying recurring problems, or improving code structure with proven patterns.
version
1.0.0
author
Kintama
license
MIT
metadata
{"hermes":{"tags":["design-patterns","GoF","architecture","OOP","structure"],"related_skills":["solid-principles","refactoring-techniques","clean-code-principles"]}}

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