{"id":19378598,"url":"https://github.com/l-super/designpattern","last_synced_at":"2026-06-12T13:31:46.007Z","repository":{"id":37637174,"uuid":"500644815","full_name":"L-Super/DesignPattern","owner":"L-Super","description":"C++ Design Pattern","archived":false,"fork":false,"pushed_at":"2025-06-27T06:33:25.000Z","size":2470,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-27T07:38:25.336Z","etag":null,"topics":["cpp","design-pattern"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/L-Super.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-07T01:13:45.000Z","updated_at":"2025-06-27T06:33:29.000Z","dependencies_parsed_at":"2025-02-24T16:19:50.014Z","dependency_job_id":"3d67d229-7a61-4a78-a2e8-b9dd075a1798","html_url":"https://github.com/L-Super/DesignPattern","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/L-Super/DesignPattern","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Super%2FDesignPattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Super%2FDesignPattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Super%2FDesignPattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Super%2FDesignPattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/L-Super","download_url":"https://codeload.github.com/L-Super/DesignPattern/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Super%2FDesignPattern/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34247460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-12T02:00:06.859Z","response_time":109,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","design-pattern"],"created_at":"2024-11-10T09:06:17.613Z","updated_at":"2026-06-12T13:31:45.974Z","avatar_url":"https://github.com/L-Super.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 设计模式是什么？\n\n**设计模式是对用来在特定场景解决一般设计问题的类和相互通信的对象的描述。**-- GOF\n\n**设计模式**是软件设计中常见问题的典型解决方案。 它们就像能根据需求进行调整的预制蓝图， 可用于解决代码中反复出现的设计问题。\n\n设计模式与方法或库的使用方式不同， 你很难直接在自己的程序中套用某个设计模式。 模式并不是一段特定的代码， 而是解决特定问题的一般性概念。 你可以根据模式来实现符合自己程序实际所需的解决方案。\n\n人们常常会混淆模式和算法， 因为两者在概念上都是已知特定问题的典型解决方案。 但算法总是明确定义达成特定目标所需的一系列步骤， 而模式则是对解决方案的更高层次描述。 同一模式在两个不同程序中的实现代码可能会不一样。\n\n算法更像是菜谱： 提供达成目标的明确步骤。 而模式更像是蓝图： 你可以看到最终的结果和模式的功能， 但需要自己确定实现步骤。\n\n一般而言，一个模式有四个基本要素：\n+ 模式名（pattern name）：助记名，描述模式的问题，解决方案和效果\n+ 问题（problem）：描述应该在合适使用模式\n+ 解决方案（solution）：描述设计的组成成分、他们之间的相互关系及各自的职责和协作方式\n+ 效果（consequence）：描述模式应用的效果及使用模式应权衡的问题\n\n## 设计模式分类\n\n不同设计模式的复杂程度、 细节层次以及在整个系统中的应用范围等方面各不相同。 我喜欢将其类比于道路的建造： 如果你希望让十字路口更加安全， 那么可以安装一些交通信号灯， 或者修建包含行人地下通道在内的多层互通式立交桥。\n\n最基础的、 底层的模式通常被称为惯用技巧。 这类模式一般只能在一种编程语言中使用。\n\n最通用的、 高层的模式是构架模式。 开发者可以在任何编程语言中使用这类模式。 与其他模式不同， 它们可用于整个应用程序的架构设计。\n\n此外， 所有模式可以根据其意图或目的来分类。 三种主要的模式类别：\n\n-   **创建型模式**：提供创建对象的机制， 增加已有代码的灵活性和可复用性。\n\t- [工厂方法模式](工厂方法.md)(Factory Method Pattern)\n\t- [抽象工厂模式](抽象工厂.md)(Abstract Factory)\n\t- [建造者模式](生成器模式.md)（Builder）\n\t- [原型模式](原型模式.md)（Prototype）\n\t- 单例模式（Singleton）\n\n-   **结构型模式**：介绍如何将对象和类组装成较大的结构， 并同时保持结构的灵活和高效。\n\t- [适配器模式](适配器模式.md)（Adapter）\n\t- [桥接模式](桥接模式.md)（Bridge）\n\t- [装饰模式](装饰模式.md)（Decorator）\n\t- [外观模式](外观模式.md)（Facade）\n\t- [享元模式](享元模式.md)（Flyweight）\n\t- [代理模式](代理模式.md)（Proxy）\n-   **行为模式**：负责对象间的高效沟通和职责委派。\n\t- [职责链模式](职责链模式.md)（Chain of Responsibility）\n\t- [命令模式](命令模式.md)（Command）\n\t- 中介者模式（Mediator）\n\t- [观察者模式](观察者模式.md)（Observer）\n\t- [状态模式](状态模式.md)（State）\n\t- [策略模式](策略模式.md)（Strategy）\n\t- [模板方法模式](模板方法模式.md)（Template Method）\n\t- [访问者模式](访问者模式.md)（Visitor）\n\n1. 创建型模式里常用的有单件和工厂，封装了对象的创建过程，隔离了对象的生产和使用；\n2. 结构型模式里常用的有适配器、外观和代理，通过对象组合，得到一个新对象，目的是适配、简化或者控制，隔离了客户代码与原对象的接口；\n3. 行为模式里常用的有职责链、命令和策略，只有在运行时才会建立联系，封装、隔离了程序里动态变化的那部分。\n\n![](image/设计模式难度分类.png)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl-super%2Fdesignpattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fl-super%2Fdesignpattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl-super%2Fdesignpattern/lists"}