{"id":21008001,"url":"https://github.com/lflxp/pattern","last_synced_at":"2026-04-21T21:07:28.715Z","repository":{"id":150080887,"uuid":"293779128","full_name":"lflxp/Pattern","owner":"lflxp","description":"设计模式","archived":false,"fork":false,"pushed_at":"2020-09-11T08:10:49.000Z","size":58,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-31T12:03:18.505Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","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/lflxp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2020-09-08T10:39:02.000Z","updated_at":"2020-09-11T08:10:51.000Z","dependencies_parsed_at":"2023-06-05T03:00:39.720Z","dependency_job_id":null,"html_url":"https://github.com/lflxp/Pattern","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lflxp/Pattern","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lflxp%2FPattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lflxp%2FPattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lflxp%2FPattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lflxp%2FPattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lflxp","download_url":"https://codeload.github.com/lflxp/Pattern/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lflxp%2FPattern/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32110198,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T11:25:29.218Z","status":"ssl_error","status_checked_at":"2026-04-21T11:25:28.499Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-11-19T09:11:09.367Z","updated_at":"2026-04-21T21:07:28.698Z","avatar_url":"https://github.com/lflxp.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 前言\n\n从1995年GoF提出23种设计模式到现在，25年过去了，设计模式依旧是软件领域的热门话题。在当下，如果你不会一点设计模式，都不好意思说自己是一个合格的程序员。设计模式通常被定义为：\n\n\u003e 设计模式（Design Pattern）是一套被反复使用、多数人知晓的、经过分类编目的、代码设计经验的总结，使用设计模式是为了可重用代码、让代码更容易被他人理解并且保证代码可靠性。\n\n从定义上看，设计模式其实是一种经验的总结，是针对特定问题的简洁而优雅的解决方案。既然是经验总结，那么学习设计模式最直接的好处就在于可以站在巨人的肩膀上解决软件开发过程中的一些特定问题。然而，学习设计模式的最高境界是习得其中解决问题所用到的思想，当你把它们的本质思想吃透了，也就能做到即使已经忘掉某个设计模式的名称和结构，也能在解决特定问题时信手拈来。\n\n好的东西有人吹捧，当然也会招黑。设计模式被抨击主要因为以下两点：\n\n1. 设计模式会增加代码量，把程序逻辑变得复杂。这一点是不可避免的，但是我们并不能仅仅只考虑开发阶段的成本。最简单的程序当然是一个函数从头写到尾，但是这样后期的维护成本会变得非常大；而设计模式虽然增加了一点开发成本，但是能让人们写出可复用、可维护性高的程序。引用《软件设计的哲学》里的概念，前者就是战术编程，后者就是战略编程，我们应该对战术编程Say No！（请移步《一步步降低软件复杂性》）\n\n2. 滥用设计模式。这是初学者最容易犯的错误，当学到一个模式时，恨不得在所有的代码都用上，从而在不该使用模式的地方刻意地使用了模式，导致了程序变得异常复杂。其实每个设计模式都有几个关键要素：适用场景、解决方法、优缺点。模式并不是万能药，它只有在特定的问题上才能显现出效果。所以，在使用一个模式前，先问问自己，当前的这个场景适用这个模式吗？\n\n《设计模式》一书的副标题是“可复用面向对象软件的基础”，但并不意味着只有面向对象语言才能使用设计模式。模式只是一种解决特定问题的思想，跟语言无关。就像Go语言一样，它并非是像C++和Java一样的面向对象语言，但是设计模式同样适用。本系列文章将使用Go语言来实现GoF提出的23种设计模式，按照创建型模式（Creational Pattern）、结构型模式（Structural Pattern）和行为型模式（Behavioral Pattern）三种类别进行组织，文本主要介绍其中的创建型模式。\n\n# 介绍\n\n[文章链接](https://zhuanlan.zhihu.com/p/177025599)\n\n本文是基于《使用Go实现GoF的23种设计模式》文章制作而成，使用`go`语言实现23种设计模式，供自己学习和备用，也提供给广大的学习爱好者一起分享。\n\n# 单元测试\n\n\u003e git clone https://github.com/lflxp/Pattern\n\u003e cd Pattern \u0026\u0026 make\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flflxp%2Fpattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flflxp%2Fpattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flflxp%2Fpattern/lists"}