# 架构模式

架构模式是针对软件架构中反复出现的问题的一种通用的、可复用的解决方案：它描述了一个系统总体结构中的关键要素、这些要素如何组合在一起，以及按此方式构建的系统往往具有哪些品质。架构模式也称为架构风格。<sup>[1](https://www.open.edu/openlearn/digital-computing/software-development-enterprise-systems/content-section-7.4.1)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 通过描述关键要素及其组合方式，以及遵循该模式所构建的系统的品质，来编纂反复出现的软件架构<sup>[1](https://www.open.edu/openlearn/digital-computing/software-development-enterprise-systems/content-section-7.4.1)</sup> |
| 规范描述 | 上下文、问题和解决方案，这一结构继承自克里斯托弗·亚历山大（Christopher Alexander）的建筑架构模式形式<sup>[2](https://ndl.ethernet.edu.et/bitstream/123456789/31382/1/Bridging%20the%20Gap%20between%20Requirements%20Engineering%20and%20Software%20Architecture.pdf)</sup> |
| 奠基文献 | Buschmann、Meunier、Rohnert、Sommerlad 和 Stal，《面向模式的软件架构：模式系统》（Wiley，1996）；Shaw 和 Garlan，《软件架构：新兴学科展望》（Prentice Hall，1996）<sup>[3](https://www.wiley-vch.de/de/fachgebiete/computer-und-informatik/a-system-of-patterns-978-0-471-95869-7)</sup><sup> • </sup><sup>[4](https://search.worldcat.org/title/Software-architecture-%3A-perspectives-on-an-emerging-discipline/oclc/797674945)</sup> |
| 示例模式 | 管道-过滤器：管道传输数据，过滤器转换数据，过滤器仅通过管道连接<sup>[1](https://www.open.edu/openlearn/digital-computing/software-development-enterprise-systems/content-section-7.4.1)</sup> |
| 与框架的区别 | 模式是针对特定问题的通用规则；框架是更具体、领域特定的部分解决方案，附带可复用代码<sup>[1](https://www.open.edu/openlearn/digital-computing/software-development-enterprise-systems/content-section-7.4.1)</sup> |
| 质量属性的作用 | 依据性能、安全性、可修改性、可靠性和可用性等质量属性对模式进行推理<sup>[5](https://www.sei.cmu.edu/library/reasoning-about-software-quality-attributes/)</sup> |
| 当前应用实例 | 微服务、模块化单体和事件驱动架构是当代广泛讨论的模式<sup>[6](https://martinfowler.com/articles/microservice-trade-offs.html)</sup><sup> • </sup><sup>[7](https://oulurepo.oulu.fi/handle/10024/51815)</sup> |

## 定义与目的

软件架构是软件系统的总体结构：它描述系统的各个部分、它们如何组合在一起，以及背后的基本原理，包括标准和经济因素等约束条件。架构模式编纂了在此类系统中反复出现的架构。它们不仅仅是描述解决方案；它们还指明如何识别问题及其上下文、应遵循何种策略，以及应用该模式所带来的后果。<sup>[1](https://www.open.edu/openlearn/digital-computing/software-development-enterprise-systems/content-section-7.4.1)</sup>

[卡内基梅隆大学](https://www.edgepedia.org/zh/carnegie-mellon-university)[软件工程研究所](https://www.edgepedia.org/zh/software-engineering-institute)（Software Engineering Institute，SEI）将架构风格定义为对组件类型及其拓扑结构的描述，连同组件之间数据和控制交互的模式，以及对该风格优缺点的非正式说明。风格作为工程制品之所以重要，是因为它们定义了具有已知属性的设计类别，携带着关于每个类别如何被使用的基于经验的证据。<sup>[8](https://www.sei.cmu.edu/library/attribute-based-architectural-styles/)</sup>

## 模式描述的结构

模式作者使用模板，以便模式可以被比较和组合。取自建筑师[克里斯托弗·亚历山大](https://www.edgepedia.org/zh/christopher-alexander)的经典三段式结构是上下文、问题和解决方案：问题产生的场景、反复出现的问题本身，以及经过充分验证的通用解决方案。<sup>[2](https://ndl.ethernet.edu.et/bitstream/123456789/31382/1/Bridging%20the%20Gap%20between%20Requirements%20Engineering%20and%20Software%20Architecture.pdf)</sup><sup> • </sup><sup>[9](https://john.cs.olemiss.edu/~hcc/softArch/98spr/notes/05patterns.html)</sup>

一个更完整的模板改编自[马丁·福勒](https://www.edgepedia.org/zh/martin-fowler-software-engineer)（Martin Fowler）——一位以企业软件架构写作而闻名的软件开发者和作家——包含五个部分：名称，足够生动以支持开发者之间的共享词汇；意图，对目的的简要陈述；工作原理部分，以与实现无关的方式描述解决方案；何时使用部分，涵盖适用性、与其他模式的关系以及权衡；以及模式使用示例。<sup>[1](https://www.open.edu/openlearn/digital-computing/software-development-enterprise-systems/content-section-7.4.1)</sup>

除非存在该模式使用的现有实例，否则模式不被接受；模式关注的是实际设计和积累的实践经验，而非新颖的方法。<sup>[1](https://www.open.edu/openlearn/digital-computing/software-development-enterprise-systems/content-section-7.4.1)</sup>

## 模式、设计模式与框架

模式文献区分了若干抽象层次。来自西门子股份公司（Siemens AG）的五位作者所著的 POSA 卷涵盖了高层架构模式、中层设计模式和底层惯用法，将它们呈现为一个系统，其中各个模式组合成更大的结构。<sup>[3](https://www.wiley-vch.de/de/fachgebiete/computer-und-informatik/a-system-of-patterns-978-0-471-95869-7)</sup>

模式不同于框架。模式是针对特定问题的通用解决方案，即规则，而框架更为具体，构成解决方案的一部分：它附带可直接复用或扩展的代码，通常服务于特定的应用领域，且通常规模更大。模式解决小问题，可以在框架内使用，但反之则不然。例如，[观察者模式](https://www.edgepedia.org/zh/observer-pattern)处理模型与其呈现之间的依赖关系，而 MVC 用户界面框架则使用观察者模式以及其他模式。<sup>[1](https://www.open.edu/openlearn/digital-computing/software-development-enterprise-systems/content-section-7.4.1)</sup>

## 经典示例

**管道-过滤器。** 该模式规定两种组件类型：管道，传输数据；过滤器，转换数据。过滤器只能通过管道连接。当系统的主要目的是通过一系列逐步转换在格式之间转换数据时，该模式非常适用；此类系统易于理解和维护，其部件可以在很大程度上复用。<sup>[1](https://www.open.edu/openlearn/digital-computing/software-development-enterprise-systems/content-section-7.4.1)</sup> Shaw 和 Garlan 1996 年的著作将管道-过滤器视为核心架构风格之一，并综述了其他风格，如分层系统、仓库和基于事件的风格。<sup>[4](https://search.worldcat.org/title/Software-architecture-%3A-perspectives-on-an-emerging-discipline/oclc/797674945)</sup>

**分层。** 分层模式被描述为许多企业模式工作的基础，将应用程序组织为逻辑层，进而驱动层内和层间的其他设计决策。<sup>[10](https://martinfowler.com/articles/enterprisePatterns.html)</sup>

**事件驱动架构。** 在该模式中，服务对称为事件的状态变化做出反应。事件是已发生事情的记录，捕获不可变的事实，可以被持久化并重复消费。生产者、事件路由器和消费者是解耦的，可以独立部署、更新和扩展；相关的事件溯源模式按应用顺序记录应用程序状态的所有变化。<sup>[11](https://docs.cloud.google.com/eventarc/standard/docs/event-driven-architectures)</sup>

## 模式与质量属性

质量属性需求，如对性能、安全性、可修改性、可靠性和可用性的需求，强烈影响系统的架构。架构师倾向于以架构模式来思考，因此 SEI 的方法以影响每个质量属性的因素来刻画模式，使用质量属性场景来陈述需求，并使用属性原语作为与质量目标相关联的设计构建块。<sup>[5](https://www.sei.cmu.edu/library/reasoning-about-software-quality-attributes/)</sup>

SEI 的基于属性的架构风格（Attribute-Based Architectural Styles，ABASs）通过将推理框架（定性或定量）显式地附加到风格上来扩展风格，使设计者能够推理设计如何实现质量目标，而不是依赖非正式的断言。<sup>[8](https://www.sei.cmu.edu/library/attribute-based-architectural-styles/)</sup> 每个模式都带有权衡：促进某一质量属性（如健壮性）的模式通常会降低其他属性，受影响的属性必须被评估，而不能想当然地认为不可接受。<sup>[12](https://www.sei.cmu.edu/blog/tactics-and-patterns-for-software-robustness/)</sup>

## 当代模式：微服务与模块化单体

**微服务。** 微服务架构风格将应用程序结构化为可独立部署的服务。马丁·福勒 2015 年被广泛引用的分析将主要好处列为强模块边界、独立部署和技术多样性，主要成本列为分布式（远程调用慢且可能失败）、最终一致性和运维复杂性。他还记录了一个他描述为被广泛接受的观点——微服务溢价：微服务带来的生产力成本只有更复杂的系统才能偿还，因此能够用单体管理其复杂性的团队不应使用微服务。<sup>[6](https://martinfowler.com/articles/microservice-trade-offs.html)</sup>

**模块化单体。** 奥卢大学（University of Oulu）的 Ruoyu Su 和 Xiaozhou Li 在 ACM 软件架构新趋势研讨会上发表的一项 2024 年研究，通过灰色文献综述考察了模块化单体，发现它结合了单体和微服务的优势，既可以作为微服务的替代方案，也可以作为迁移到微服务之前的过渡步骤。在谷歌提出 Service Weaver 框架之后，人们的兴趣增长了，该框架让开发者将应用程序编写为模块化单体，并将其作为一组微服务部署。<sup>[7](https://oulurepo.oulu.fi/handle/10024/51815)</sup> 一项对从业者会议的五年回顾同样指出，从单体系统向微服务的广泛转变，随后是对这一转变的重新审视以及向单体的回归。<sup>[13](https://www.sciencedirect.com/science/article/pii/S0164121226000543)</sup>

**可组合企业风格。** MACH 架构——代表微服务、API 优先、云原生和无头——是一种模块化的、技术无关的企业方法。该概念可追溯到 2020 年，当时 MACH 联盟由 [Contentstack](https://www.edgepedia.org/zh/contentstack)、Commercetools、EPAM Systems 和 Valtech 成立；该联盟 2025 年对 561 家公司的调查预测，到 2026 年企业技术栈的 61% 将基于 MACH。<sup>[14](https://www.itpro.com/software/what-is-mach-architecture)</sup>

## 验证与证据

模式是在实践中被观察到之后才被记录的，通常至少三次，但研究者指出，这种便利样本往往提供有限的效度证据。一项关于微服务模式的实证研究就 14 种模式和 7 个质量属性采访了九位从业者；许多报告的权衡与模式的文档记载相符，该研究还识别出了此前未报告的收益和痛点。<sup>[15](https://arxiv.org/abs/2201.03598)</sup> 关于微服务中面向性能的模式的实验工作同样得出结论，评估模式性能是复杂的，理论模型需要用经验数据来补充。<sup>[16](https://arxiv.org/abs/2409.03792)</sup>

## References

1. [Software development for enterprise systems: 7.4.1 Architectural patterns, The Open University, OpenLearn](https://www.open.edu/openlearn/digital-computing/software-development-enterprise-systems/content-section-7.4.1)
2. [Bridging the Gap between Requirements Engineering and Software Architecture (chapter on software architecture concepts)](https://ndl.ethernet.edu.et/bitstream/123456789/31382/1/Bridging%20the%20Gap%20between%20Requirements%20Engineering%20and%20Software%20Architecture.pdf)
3. [Pattern-Oriented Software Architecture: A System of Patterns, Wiley-VCH book page](https://www.wiley-vch.de/de/fachgebiete/computer-und-informatik/a-system-of-patterns-978-0-471-95869-7)
4. [Software architecture: perspectives on an emerging discipline, WorldCat record](https://search.worldcat.org/title/Software-architecture-%3A-perspectives-on-an-emerging-discipline/oclc/797674945)
5. [Reasoning About Software Quality Attributes, CMU Software Engineering Institute](https://www.sei.cmu.edu/library/reasoning-about-software-quality-attributes/)
6. [Martin Fowler (2015). Microservice Trade-Offs](https://martinfowler.com/articles/microservice-trade-offs.html)
7. [Su, R., & Li, X. (2024). Modular Monolith: Is This the Trend in Software Architecture? SATrends '24](https://oulurepo.oulu.fi/handle/10024/51815)
8. [Klein, M., & Kazman, R. (1999). Attribute-Based Architectural Styles, CMU/SEI-99-TR-022](https://www.sei.cmu.edu/library/attribute-based-architectural-styles/)
9. [ENGR 691 Software Architecture lecture notes: Pattern Introduction, University of Mississippi](https://john.cs.olemiss.edu/~hcc/softArch/98spr/notes/05patterns.html)
10. [Martin Fowler (2005). Patterns in Enterprise Software](https://martinfowler.com/articles/enterprisePatterns.html)
11. [Event-driven architectures, Google Cloud documentation](https://docs.cloud.google.com/eventarc/standard/docs/event-driven-architectures)
12. [Tactics and Patterns for Software Robustness, CMU Software Engineering Institute blog](https://www.sei.cmu.edu/blog/tactics-and-patterns-for-software-robustness/)
13. [Emerging trends in software architecture from the practitioner's perspective: A five-year review, Journal of Systems and Software](https://www.sciencedirect.com/science/article/pii/S0164121226000543)
14. [What is MACH architecture? ITPro](https://www.itpro.com/software/what-is-mach-architecture)
15. [Designing Microservice Systems Using Patterns: An Empirical Study on Quality Trade-Offs, arXiv:2201.03598](https://arxiv.org/abs/2201.03598)
16. [Experimental evaluation of architectural software performance design patterns in microservices, arXiv:2409.03792](https://arxiv.org/abs/2409.03792)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Software engineering and development process › Software design and architecture › Titles 4 to Mo

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/architectural-pattern

English original: https://www.edgepedia.org/architectural-pattern
