Software Design 标志

Software Design

社区
Tibsfox
software-design

Software design principles, patterns, and architecture from SOLID through distributed systems. Covers the five SOLID principles with violations and fixes, DRY/KISS/YAGNI heuristics, separation of concerns, 12 GoF design patterns organized by intent (creational, structural, behavioral), architectural patterns (MVC, MVP, MVVM, layered, hexagonal, microservices, event-driven), coupling and cohesion metrics, dependency injection, and the design decision framework for choosing between competing approaches. Use when making design decisions, reviewing architecture, refactoring code, or teaching software engineering principles.

概览

发布者Tibsfox
代码仓库gsd-skill-creator
技能名称software-design
星标数
70
复刻数
9
附带文件
仅含指令
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 指令自成一体

    模型所需的一切都包含在指令中,无需同步额外文件。

  • 开源

    由 Tibsfox 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Software Design AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/Tibsfox/gsd-skill-creator/tree/main/examples/skills/coding/software-design
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Tibsfox/gsd-skill-creator.git /tmp/gsd-skill-creator
mkdir -p .claude/skills
cp -r /tmp/gsd-skill-creator/examples/skills/coding/software-design .claude/skills/software-design
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Software Design,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Software Design。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Software Design 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Software Design

Software design is the discipline of organizing code so that it is correct, understandable, and changeable. A well-designed system makes the right things easy and the wrong things hard. This skill catalogs the principles, patterns, and architectural styles that professional software engineers use to achieve this, with emphasis on when each applies and when it does not.

Agent affinity: dijkstra (structured programming, formal reasoning about design), kay (OOP, message-passing architecture)

Concept IDs: code-code-organization, code-abstraction, code-decomposition, code-peer-review

Part 1 -- Design Principles

The SOLID Principles

Robert C. Martin codified these five principles for object-oriented design. They apply more broadly to any modular system.

S -- Single Responsibility Principle (SRP)

Statement: A module should have one, and only one, reason to change.

What it means. Each class, function, or module should serve exactly one purpose. If you change the database schema, only the database layer should change. If you change the UI layout, only the UI layer should change.

Violation signal. A class that has methods for both parsing user input AND writing to the database. A function that both validates data AND sends an email.

Fix. Separate the responsibilities into distinct modules. A UserValidator validates; a UserRepository persists; an EmailService sends.

O -- Open/Closed Principle (OCP)

Statement: Software entities should be open for extension but closed for modification.

What it means. You should be able to add new behavior without changing existing, tested code. This is achieved through abstraction -- interfaces, abstract classes, or polymorphism.

Violation signal. A function with a growing chain of if/else or switch statements that must be modified every time a new case is added.

Fix. Define an interface that each case implements. New cases add a new implementation without touching existing code. The Strategy pattern is the canonical implementation of OCP.

L -- Liskov Substitution Principle (LSP)

Statement: Objects of a supertype should be replaceable with objects of a subtype without breaking the program.

What it means. Subclasses must honor the contract of their parent. If a function works with a Shape, it must work with Circle, Rectangle, and Triangle without knowing which one it has.

The classic violation. Square extends Rectangle. A function sets width to 5 and height to 10, then asserts area == 50. The Square overrides setWidth to also set height, so area == 100. The substitution broke the contract.

Fix. Do not make Square a subclass of Rectangle. Model them as siblings implementing a common Shape interface, or use composition instead of inheritance.

I -- Interface Segregation Principle (ISP)

Statement: No client should be forced to depend on methods it does not use.

What it means. Large interfaces should be split into smaller, more specific ones. A Printer interface with print(), scan(), fax(), and staple() forces a simple printer to implement fax() and staple() with stubs or exceptions.

Fix. Split into Printable, Scannable, Faxable. Clients depend only on the interfaces they use. Composition of small interfaces is more flexible than one large interface.

D -- Dependency Inversion Principle (DIP)

Statement: High-level modules should not depend on low-level modules. Both should depend on abstractions.

What it means. The business logic should not import the database driver directly. Instead, both the business logic and the database implementation depend on a Repository interface. This makes the database swappable without changing the business logic.

Implementation. Dependency injection: pass dependencies as constructor parameters or function arguments rather than creating them internally. This also enables testing -- inject a mock repository in tests, a real one in production.

Complementary Heuristics

DRY (Don't Repeat Yourself). Every piece of knowledge should have a single, unambiguous, authoritative representation. Duplication is a maintenance liability. But premature de-duplication (abstracting too early) can be worse than duplication -- wait until you see the pattern three times (the Rule of Three).

KISS (Keep It Simple, Stupid). The simplest solution that works is the best solution. Complexity is a cost, not a feature. Every abstraction layer, design pattern, and framework adds complexity that must be justified by the problems it solves.

YAGNI (You Aren't Gonna Need It). Do not build features, abstractions, or flexibility for hypothetical future requirements. Build what you need now. When the future requirement arrives, you will understand it better and build a more appropriate solution.

Separation of Concerns. Each module addresses a separate concern. The UI does not contain business logic. The business logic does not contain database queries. The database layer does not format HTTP responses. This is the meta-principle behind SOLID, MVC, and layered architecture.

Coupling and Cohesion

Coupling measures how much modules depend on each other. Low coupling means modules can be changed independently. High coupling means a change in one module cascades through many others.

Cohesion measures how closely related the elements within a module are. High cohesion means a module does one thing well. Low cohesion means a module is a grab-bag of unrelated functionality.

The goal: high cohesion within modules, low coupling between modules. This is the quantitative formulation of good design.

Part 2 -- Design Patterns

Design patterns are reusable solutions to common design problems. They are not code templates -- they are conceptual tools for structuring interactions between objects and modules. The Gang of Four (GoF) cataloged 23 patterns in 1994; the 12 most practically important are covered here.

Creational Patterns

Factory Method

Problem: Client code needs to create objects but should not know the concrete class.

Solution: Define a method that returns an instance of an interface. Subclasses or configuration determine the concrete class.

When to use. When the creation logic is complex, when the concrete class depends on runtime conditions, or when you want to decouple client code from implementation classes.

Builder

Problem: Constructing complex objects with many optional parameters leads to telescoping constructors or error-prone parameter ordering.

Solution: Separate the construction of a complex object from its representation. The builder accumulates configuration and produces the final object in a build() call.

When to use. Objects with more than 3-4 optional parameters. Immutable objects that require all fields at construction time. Configuration objects.

Singleton

Problem: Ensure a class has exactly one instance and provide a global access point.

Solution: Private constructor, static instance method.

When to use. Almost never. Singleton is the most overused pattern. It creates hidden global state, makes testing difficult, and couples all consumers to the singleton. Prefer dependency injection. Use singleton only for truly global, stateless services (logging, metrics) and even then consider alternatives.

Structural Patterns

Adapter

Problem: Two interfaces are incompatible but need to work together.

Solution: Create a wrapper that translates calls from one interface to the other.

When to use. Integrating third-party libraries, wrapping legacy APIs, bridging between different data formats.

Decorator

Problem: Add behavior to an object dynamically without modifying its class.

Solution: Wrap the object in a decorator that implements the same interface and adds behavior before or after delegating to the wrapped object.

When to use. Middleware chains (logging, authentication, caching), stream transformations, adding features to sealed classes.

Facade

Problem: A complex subsystem has many interacting classes that clients should not need to understand.

Solution: Provide a simplified interface that hides the complexity behind a single entry point.

When to use. Wrapping complex libraries, providing a simplified API for common use cases, reducing the learning curve for new developers.

Behavioral Patterns

Strategy

Problem: An algorithm needs to be selected at runtime from a family of alternatives.

Solution: Define an interface for the algorithm. Each variant implements the interface. The context holds a reference to the current strategy and delegates to it.

When to use. Sorting strategies, payment processing methods, validation rules, rendering backends. This is the canonical implementation of the Open/Closed Principle.

Observer

Problem: One object changes state and multiple other objects need to be notified without tight coupling.

Solution: Define a subscription mechanism. Observers register interest in a subject. When the subject's state changes, it notifies all registered observers.

When to use. Event systems, UI data binding, pub/sub messaging, reactive programming.

Iterator

Problem: Traverse a collection without exposing its internal structure.

Solution: Define a standard interface (hasNext/next or the language's iterator protocol) that produces elements one at a time.

When to use. Any collection traversal. Most modern languages have built-in iterator support (Python's for/in, JavaScript's Symbol.iterator, Rust's Iterator trait).

Command

Problem: Encapsulate a request as an object so it can be parameterized, queued, logged, or undone.

Solution: Create a command object with an execute() method (and optionally undo()). The invoker holds commands and executes them without knowing what they do.

When to use. Undo/redo systems, task queues, macro recording, transaction logs.

State

Problem: An object's behavior changes based on its internal state, leading to complex conditionals.

Solution: Encapsulate each state as a separate class implementing a common interface. The context delegates to the current state object.

When to use. State machines (UI components, protocol handlers, game entities), workflow engines.

Template Method

Problem: Multiple algorithms share a common structure but differ in specific steps.

Solution: Define the skeleton in a base class method, with abstract methods for the varying steps. Subclasses implement the abstract methods.

When to use. Framework hooks (test setup/teardown, request processing pipelines), algorithms with fixed structure and variable details.

Part 3 -- Architectural Patterns

MVC (Model-View-Controller)

Model: Data and business logic. Notifies observers when state changes. View: UI presentation. Reads from the model, renders output. Controller: Handles user input, updates the model.

When to use. Web applications (Rails, Django, Spring MVC), desktop applications. The most widely known architectural pattern.

Variants. MVP (Model-View-Presenter) -- the presenter mediates all communication between view and model, making the view passive and testable. MVVM (Model-View-ViewModel) -- the view model exposes observable properties that the view binds to declaratively (WPF, SwiftUI, Vue.js).

Layered Architecture

Layers (top to bottom): Presentation -> Business Logic -> Data Access -> Database.

Each layer depends only on the layer directly below it. This enforces separation of concerns and makes layers independently replaceable. The strict boundary rule in this project (src/ never imports desktop/) is a layered architecture constraint.

Hexagonal Architecture (Ports and Adapters)

Core: Business logic with no external dependencies. Ports: Interfaces that the core defines for its needs (input ports for use cases, output ports for persistence). Adapters: Implementations of ports for specific technologies (REST adapter, PostgreSQL adapter, CLI adapter).

Why it matters. The business logic is testable in isolation. Technology decisions (which database, which framework) are pushed to the edges and can be changed without touching the core.

Microservices

Principle: Decompose a system into small, independently deployable services, each owning its data and communicating via well-defined APIs.

When to use. Large teams where independent deployment matters, systems with genuinely different scaling requirements per component, polyglot environments.

When NOT to use. Small teams, early-stage products, systems where the domain boundaries are unclear. The distributed systems overhead (network latency, partial failure, eventual consistency, observability) is substantial. Start with a modular monolith.

Event-Driven Architecture

Principle: Components communicate by producing and consuming events rather than making direct calls. Decouples producers from consumers.

When to use. Systems with many independent reactions to the same event, audit/logging requirements, eventual consistency is acceptable.

Key patterns. Event sourcing (store events, not state), CQRS (separate read and write models), saga pattern (coordinate distributed transactions via events).

Design Decision Framework

When choosing between competing approaches, evaluate along these dimensions:

DimensionQuestion
SimplicityWhich approach has fewer moving parts?
TestabilityWhich is easier to test in isolation?
ChangeabilityWhich requires fewer changes when requirements evolve?
UnderstandabilityWhich can a new developer understand fastest?
PerformanceDoes it matter? Measure, don't guess.
Team capabilityDoes the team have experience with this approach?

The first dimension wins ties. When two approaches are equally good on other dimensions, choose the simpler one. Complexity is a liability that compounds over time.

Common Mistakes

MistakeWhy it failsFix
Premature abstractionAbstracts before the pattern is clearWait for three instances (Rule of Three)
Pattern worshipForces patterns where they add complexity without valuePatterns are tools, not goals
God classOne class does everythingSplit along responsibility boundaries (SRP)
Leaky abstractionImplementation details leak through the interfaceReview interface contracts, hide internals
Inheritance for code reuseTight coupling, fragile base class problemPrefer composition over inheritance
Distributed monolithMicroservices that must be deployed togetherEither make them independent or merge them
Premature microservicesDistributed complexity without the benefitsStart with a modular monolith

Cross-References

  • dijkstra agent: Structured programming, formal reasoning about program correctness, "Go To considered harmful."
  • kay agent: Object-oriented design, message passing, late binding, Smalltalk philosophy.
  • knuth agent: Algorithm-level design decisions, literate programming as a design discipline.
  • lovelace agent: Architectural vision, seeing computation as more than calculation.
  • programming-fundamentals skill: The building blocks that design principles organize.
  • debugging-testing skill: Testing strategies that validate design decisions.

References

  • Martin, R. C. (2017). Clean Architecture. Prentice Hall.
  • Gamma, E., Helm, R., Johnson, R., & Vlissides, J. (1994). Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley.
  • Fowler, M. (2002). Patterns of Enterprise Application Architecture. Addison-Wesley.
  • Dijkstra, E. W. (1968). "Go To Statement Considered Harmful." Communications of the ACM, 11(3), 147-148.
  • Kay, A. (1993). "The Early History of Smalltalk." ACM SIGPLAN Notices, 28(3), 69-95.
  • Cockburn, A. (2005). "Hexagonal Architecture." alistair.cockburn.us.
  • Newman, S. (2021). Building Microservices. 2nd edition. O'Reilly.

常见问题

Software Design AI 技能有什么作用?

Software design principles, patterns, and architecture from SOLID through distributed systems. Covers the five SOLID principles with violations and fixes, DRY/KISS/YAGNI heuristics, separation of concerns, 12 GoF design patterns organized by intent (creational, structural, behavioral), architectural patterns (MVC, MVP, MVVM, layered, hexagonal, microservices, event-driven), coupling and cohesion metrics, dependency injection, and the design decision framework for choosing between competing approaches. Use when making design decisions, reviewing architecture, refactoring code, or teaching so...

为什么在 TypingMind 中使用 Software Design?

因为您只需安装一次,就能搭配任何模型使用。Software Design 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Software Design?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/Tibsfox/gsd-skill-creator/tree/main/examples/skills/coding/software-design。TypingMind 会读取其中的 SKILL.md,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Software Design?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Software Design 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Software Design 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Software Design AI 技能免费吗?

Tibsfox 已在 GitHub 上发布了该技能。请查看代码仓库了解许可条款。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇