Token导航 LogoToken导航TokenDH.com
研究检索只读github未标认证来源可访问许可证需确认审计通过

design-pattern设计模式

Agent Skill

用于辅助界面设计、视觉规范、排版、配色、布局和交互体验优化。它适合让 Agent 根据产品场景整理页面结构、生成 UI 方案、检查视觉一致性或改进组件层级。使用时需要结合现有品牌、设计系统和用户任务,不应只堆装饰元素;涉及真实页面改动时,应通过截图或浏览器预览检查文本溢出、对齐和响应式表现。

总安装

539

周安装

22

GitHub Stars

公开资料未说明

下载量

174
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:design-pattern(设计模式)
来源仓库:https://github.com/cylixlee/skills
仓库路径:skills/design-pattern
安装命令:
npx skills add https://github.com/cylixlee/skills --skill design-pattern
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/cylixlee/skills --skill design-pattern

简介

应用软件设计原则生成高可维护代码,避免过度抽象与冗余。

  • 坚持 YAGNI 原则,仅在需要时引入接口与分层架构。
  • 使用时需优先考虑简单解决方案,延迟复杂模式的应用。
  • 安装方式:GitHub,命令为 npx skills add https://github.com/cylixlee/skills --skill design-pattern。
  • 注意:核心目标是代码可读性与扩展性,而非追求模式覆盖率。

SKILL.md

Design Pattern

This skill guides the generation of high-quality, maintainable, and extensible code by applying established software design principles. When generating code for any non-trivial application, always follow these principles to ensure the resulting codebase is easy to understand, modify, test, and extend over time.

Core Principles

1. Simplicity First

Always prefer simple solutions over complex ones. Do not over-engineer or add abstraction layers that are not yet needed.

YAGNI (You Aren't Gonna Need It)

Do not design abstractions "just in case" they might be needed later. Implement what is needed now, and refactor when actual extension requirements arise. Premature abstraction often leads to incorrect interfaces that must be changed anyway.

KISS (Keep It Simple, Stupid)

Simple code is easier to understand, test, and maintain. If a simple solution works, use it. Complexity should be added only when there is a clear, immediate need.

2. Interface Design

Prefer Standard Library Interfaces

When the standard library or language provides an interface that meets your needs, use it. Do not create custom interfaces that duplicate standard ones. For example, in Go use io.Reader and io.Writer instead of defining your own Reader or Writer interfaces.

Define Interfaces at the Point of Need

Define interfaces where they are consumed, not at a central location. This reduces unnecessary coupling and allows interfaces to be specific to actual use cases.

3. Package and Module Organization

Name Packages by Purpose, Not Project Name

Name packages based on what they do, not the project name. For example, a parser package should be called "parser" or "parsing", not "brainvm".

Follow Language Conventions

Use the project structure and conventions appropriate for the language:

  • Go: Single program → root main.go, multiple programs → cmd/ folder, library → functional packages
  • Java: Standard Maven/Gradle structure with src/main/java
  • Python: src/ or flat structure with __init__.py
  • Do not assume all languages have the same conventions (not all languages have cmd/)

4. Layered Architecture

Layered Architecture is essential for maintainable software because it separates concerns, making code easier to understand, test, and modify. When all code is mixed together in a single layer, changes in one area can unexpectedly break unrelated functionality. By separating responsibilities into distinct layers, each layer can be developed, tested, and modified independently.

The key principle is that dependencies should only flow in one direction, typically from outer layers toward inner layers. This ensures that core business logic does not depend on external concerns like databases, UI frameworks, or external services.

Why Layered Architecture Matters

  • Separation of Concerns: Each layer has a single, well-defined responsibility
  • Testability: Inner layers can be tested without involving outer layers
  • Maintainability: Changes to one layer (e.g., switching databases) don't affect other layers
  • Reusability: Core business logic can be reused across different interfaces
  • Parallel Development: Different teams can work on different layers simultaneously

Common Layering Approaches

Model-View-Controller (MVC): A pattern that separates an application into three main components: the Model (data and business logic), the View (presentation layer), and the Controller (handles user input and orchestrates Model and View). MVC is particularly common in web applications and UI frameworks.

Domain-Driven Design (DDD): DDD emphasizes modeling software around business domains. It uses concepts like entities, value objects, aggregates, bounded contexts, and domain services. DDD is particularly valuable for complex business applications where the domain logic is sophisticated and frequently changing. For more details, see Domain-Driven Design.

General Rule

Regardless of the specific layering approach chosen, always ensure:

  • Each layer has clear, single responsibility
  • Dependencies flow inward only
  • Layer boundaries are enforced through interfaces or abstractions
  • Code is distributed across multiple files and packages, not lumped together

Avoid Unnecessary Middle Layers

Do not create abstraction layers that merely wrap other layers without adding value. Only create a new layer when there is a clear separation of concerns that genuinely needs it. If two components naturally belong together, keep them together.

2. OOP Over Imperative

Write code using Object-Oriented Programming principles rather than procedural or functional style. OOP provides better abstraction, encapsulation, and polymorphism for building complex systems.

Use Interfaces or Abstract Classes to Define Contracts

Always define the "what" separately from the "how". Define what operations are available through an interface or abstract class, then provide concrete implementations. This allows clients to depend on abstractions rather than specific implementations, enabling flexibility and testability.

Prefer Composition Over Inheritance

Favor "has-a" relationships over "is-a" relationships. Inheritance creates tight coupling between classes, making changes difficult and testing problematic. Composition (组装) allows you to combine behaviors by injecting dependencies, which is more flexible and easier to test.

Encapsulate Behavior Within Classes

Keep related behavior and data together. Avoid scattered utility functions or global state. Each class should bundle its data with the operations that manipulate that data.

Extract Hardcoded Logic to Strategy Classes

When you find conditional logic that varies by type or category, consider extracting each variant into its own class. This follows the Strategy pattern and makes the code easier to extend without modification.

3. SOLID Principles

Apply these five principles as code quality checks. Whenever you write code, verify that it does not violate any SOLID principle.

Single Responsibility Principle

Every class should have only one reason to change. A class should do one thing well. If a class is responsible for multiple concerns, changes to one concern may affect others unexpectedly.

Open/Closed Principle

Software entities should be open for extension but closed for modification. Add new features by adding new code rather than modifying existing code. This is typically achieved through abstraction, polymorphism, and composition.

Liskov Substitution Principle

Subtypes must be substitutable for their base types. A subclass should honor the contract of its parent class. If a subclass cannot fully implement parent behavior, the inheritance relationship is incorrect.

Interface Segregation Principle

Clients should not be forced to depend on interfaces they do not use. Many small, specific interfaces are better than one large interface. This prevents classes from being burdened with methods they don't need.

Dependency Inversion Principle

High-level modules should not depend on low-level modules. Both should depend on abstractions. This enables swapping implementations without affecting clients.

4. Design Pattern Selection

Design patterns are reusable solutions to commonly occurring problems. Choose appropriate patterns based on the specific problem context.

How to Use Design Pattern References

  1. Analyze the problem: First, understand what problem you need to solve
  2. Select the pattern: Choose the appropriate design pattern from the tables below based on the problem type
  3. Choose implementation: Navigate to references/{pattern-name}/{language}.md for your target language
  4. Apply with care: Remember that patterns are tools, not rules - use them when they fit

Creation Patterns

PatternPurposeGoJavaPython
Factory MethodDelegate instantiation to subclassesGoJavaPython
Abstract FactoryCreate families of related objectsGoJavaPython
BuilderConstruct complex objects step by stepGoJavaPython
SingletonEnsure single instance with global accessGoJavaPython
PrototypeCreate objects by cloning existing onesGoJavaPython

Structural Patterns

PatternPurposeGoJavaPython
AdapterConvert interface compatibilityGoJavaPython
BridgeSeparate abstraction from implementationGoJavaPython
CompositeTree structures for part-whole hierarchiesGoJavaPython
DecoratorAdd responsibilities dynamicallyGoJavaPython
FacadeSimplified interface to complex subsystemGoJavaPython
FlyweightShare common state efficientlyGoJavaPython
ProxyControl access to another objectGoJavaPython

Behavioral Patterns

PatternPurposeGoJavaPython
Chain of ResponsibilityPass request along a chain of handlersGoJavaPython
CommandEncapsulate request as an objectGoJavaPython
IteratorAccess elements sequentiallyGoJavaPython
MediatorCentralized communicationGoJavaPython
MementoCapture and restore internal stateGoJavaPython
ObserverNotify dependents of state changesGoJavaPython
StateAlter behavior based on internal stateGoJavaPython
StrategyInterchangeable algorithmsGoJavaPython
Template MethodDefine algorithm skeleton, let subclasses override stepsGoJavaPython
VisitorOperations on elements of an object structureGoJavaPython

5. Dependency Management

Proper dependency management is critical for maintainability and testability.

Use Dependency Injection

Inject dependencies rather than creating them inside classes. Pass dependencies through constructors or setters rather than having classes create their own dependencies. This enables loose coupling and makes testing straightforward.

Inject Abstractions, Not Concretions

Always depend on interfaces or abstract types, not concrete implementations. This allows implementations to be swapped without affecting client code.

Avoid Circular Dependencies

Circular dependencies make code hard to test and reason about. The dependency graph should be acyclic. If two modules depend on each other, extract shared abstractions to break the cycle.

6. Testability

Design code to be easily testable. Testable code is usually well-designed code.

  • Avoid static state that persists between tests
  • Avoid singletons with mutable state
  • Use dependency injection to enable mocking
  • Favor pure functions where possible
  • Keep methods focused and single-purpose

7. Code Quality Rules

  • Meaningful Naming: Use descriptive names for classes, methods, and variables that convey intent
  • Short Methods: Each method should do one thing; keep methods concise
  • No Duplication: Extract repeated logic into reusable abstractions (DRY principle)
  • Error Handling: Use exceptions rather than error codes; provide meaningful error messages

8. Anti-Patterns to Avoid

  • God Class: A class with too many responsibilities; split into focused classes
  • Spaghetti Code: Tangled, unstructured control flow; apply proper design
  • Magic Values: Hardcoded numbers or strings without constants; use named constants
  • Premature Optimization: Optimize only when measurement proves it necessary
  • Excessive Inheritance: Deep hierarchies create tight coupling; prefer composition
  • Over-Engineering: Creating unnecessary abstraction layers, interfaces, or packages that don't yet have clear use cases
  • Interface Duplication: Defining custom interfaces that duplicate standard library interfaces (e.g., defining your own Reader when io.Reader exists)
  • Premature Abstraction: Creating generic interfaces or base types before actual variation points are understood
  • Unused Code: "var _ Interface = (*Implementation)(nil)" style compile-time checks that serve no practical purpose

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.92%
按下载量换算63

Claude

30.34%
按下载量换算53

Cursor

18.67%
按下载量换算32

Gemini CLI

8.31%
按下载量换算14

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills