--- tags: Design Pattern --- Design Pattern === ###### tags: `Design Pattern` {%hackmd BJrTq20hE %} [Software Design & Architecture Stack](https://khalilstemmler.com/articles/software-design-architecture/full-stack-software-design/) 12/08 (Nathan) Clean Architecture ![Clean Architecture](https://i.imgur.com/lmBYQM8.png) 軟體複雜性 --- [Ref](https://zhuanlan.zhihu.com/p/96038795) 12/08 (Nathan) Layered Architecture --- [Hexagonal Architecture](https://www.jianshu.com/p/c2a361c2406c) [何为整洁架构?](https://juejin.cn/post/6844903757713522701) [演講ITkonekt 2019 | Robert C. Martin (Uncle Bob), Clean Architecture and Design](https://www.youtube.com/watch?v=2dKZ-dWaCiU&feature=youtu.be) [干净架构 - Clean Architecture](https://zhuanlan.zhihu.com/p/259599099) [如何评价 Bob 大叔的新书《架构整洁之道》?](https://www.zhihu.com/question/301498382/answer/1018334384) [阿里巴巴-架构整洁之道](https://mp.weixin.qq.com/s/Kd1T40KZWvdThKC3IN6n-Q) ``` 好架构的特点 A good architecture allows major decisions to be DEFERRED! A good architecture maximizes the number of decisions NOT made 设计架构时最容易犯得错误就是先关注细节,例如用什么数据库,用什么框架,但是这些都不是最重要的,架构最需要关注的是 系统存在的原因,背景,目的 系统在做什么,解决什么问题 use cases 什么业务模型能更好的满足 use cases 为了不关心具体的 IO 设备,发明了 standard out ,这种抽象使工程师不在关心 IO 设备这种细节 建筑物的架构不会包含用什么材料做的细节,而是包含这个架构是为了做什么,解决什么问题 ``` Design Principles --- - [SOLID](/fiYx0urIShSzyAfvYekfLw) 12/08 (Nathan) - [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) - [YAGNI](/X86i_jUrR92-kb2DRJov8g) - [Compostion over Inheritance](https://en.wikipedia.org/wiki/Composition_over_inheritance) - [Hollywood Principle](https://ithelp.ithome.com.tw/articles/10223248) - [More OOAD Principles](https://ithelp.ithome.com.tw/articles/10214852) Design Pattern --- [Refactoring GURU](https://refactoringguru.cn/) [SourceMaking](https://sourcemaking.com/) [设计模式简介](https://www.runoob.com/design-pattern/design-pattern-intro.html) [24种设计模式的总结及学习设计模式的几点建议](https://zhuanlan.zhihu.com/p/72188325) [23种经典设计模式的原理、背后的思想、应用场景](https://zhuanlan.zhihu.com/p/345126462) - 設計模式三元素 ```每一個Pattern都是在某個環境(Context)下, 針對某Problem, 提出的Solution``` - Context - Problem - Solution - Design Pattern的好處 - 提供設計的客觀唯度度量 - **再**利用的解決方案 - 建立**通用**術語 - 提昇軟體設計品質 - 嘗試分析每個模式的 - Intent (意圖/目的) - Motivation (動機/解決什麼問題?) - Applicability (適用場景) - Structure (類別圖) - Participants (參與者/角色說明) - Collaborations (角色之間的互動說明) - Consequences (優缺) - Implementations (不同語言的實作方法) - 模式目錄 - [Creational](/fiYx0urIShSzyAfvYekfLw) - [Factory (12/15 阿壹)](/89aCMY2lScqfahMNAbiojQ) - [Abstract Factory (12/15 阿壹)](/TCjoZ_CaQBiRKmGCISR8-w) - [Builder (12/22 Nathan WU)](/XREpfHTGT0aZa0eIb2dVzQ) - [Prototype (12/29 Eddie.C)](https://www.notion.so/Prototype-Pattern-c63b2aa3b7d14a5380ddfe04ef322ea2) - Singleton (12/29 GSON) - [Structral](/fiYx0urIShSzyAfvYekfLw) - [Bridge (1/5 Nathan)](/AzxBeqQnSX6YZr3v8PHHbg) - [Adapter (1/12 GSON)](https://hackmd.io/FBRH4ZynT-WMr4OjxE52eg?view) - Facade (1/19 Nathan WU) - [Flyweight (1/19 Nathan)](/tXDrXFItRkeZVmDHumgupA) - [Composite (1/26 Nathan)](https://hackmd.io/0RQEYLTJT-qZsJAj9vUW4w) - Proxy + Repository Pattern (2/2 GSON) - [Decorator (2/23 Eddie.C)](https://www.notion.so/bc6eec37f2fa47b8900a6beccb724eab) - Null Object - [Behavioral](/fiYx0urIShSzyAfvYekfLw) - [Command (3/2 GSON)](/YnJHGO59SwKMJ_ueOTHIig) - Chain of Responsibility (3/9 JJ) - [Memento (3/9 Nathan)](/DDmreDWrS2m8frH1-lLXOA) - Iterator (3/16 Eddie.C) ~~- [Visitor (3/ Nathan)](/jKmw4D1wToOTFa291cKjrQ)~~ - Template Method (3/23 Nathan) - Observer (3/30 GSON) - 與Pub/Sub模式的差別 - Mediator (4/6 JJ) - Strategy (4/13 阿壹) - [參考91-用多型取代重複的判斷式](https://tdd.best/code-4-fun/polymorphism-replace-conditions/) - Q: Strategy跟Factory 有些相似? - Q: Strategy與責任鍊的差異? - State (4/20 JJ) - [Concurrency](https://openhome.cc/Gossip/DesignPattern/index.html) - Thread-Per-Message Pattern - Active Object - Reactor - Monitor Object - [MicroService Pattern] - [Anti Pattern](https://en.wikipedia.org/wiki/Anti-pattern) - [每个程序员都应注意的9种反面模式](https://blog.csdn.net/long316/article/details/51880257?utm_medium=distribute.pc_relevant.none-task-blog-OPENSEARCH-3.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-OPENSEARCH-3.control) - [Singleton Pattern 使用反思](https://medium.com/@lojungyun/singleton-pattern-%E4%BD%BF%E7%94%A8%E5%8F%8D%E6%80%9D-d2b4fcef31af) 參考文章 --- - [设计模式浅谈——抽象和解耦](https://zhuanlan.zhihu.com/p/53006303) - [程式碼可讀性之簡報介紹vol. 4: “相依關係” 篇](https://engineering.linecorp.com/zh-hant/blog/code-readability-vol4/) - [Software Design --- Cohesion內聚, Coupling耦合](https://a28283878.github.io/documents/Cohesion-Coupling.html) - [为何大量设计模式在动态语言中不适用?](https://www.zhihu.com/question/63734103/answer/212353641) - [设计模式有何不妥,所谓的荼毒体现在哪?](https://www.zhihu.com/question/23757237/answer/25564019) - [为什么我们需要学习(设计)模式](https://zhuanlan.zhihu.com/p/19835717) - [如何正确地使用设计模式?](https://www.zhihu.com/question/23757906/answer/1403760592) - [搞笑談軟工](http://teddy-chen-tw.blogspot.com/search/label/Patterns) - Triton Ho 單例模式討論串: ``` singleton pattern多一點感想吧: 很多人會覺得db connection pool / redis connection pool一個系統只會有一個⋯⋯ 而現實上,有時是為了容易debug(不管是logical bug還是performance bug),或是更好的災情控制(別讓一個bug讓系統全面崩潰),或是保安理由(最保密的資料獨立地存放) 當你的流量越來越高,你的系統複雜度越來越高。 你很自然的就會有multiple db / redis要用上的。 然後如果你用上傳統的singleton pattern,讓你db conn pool obj只有一個 然後你每段application logic都是 dbClass.GetDBpool().GetConn() 你在分拆db時一定會改到哭哭。 所以Dependency Injection,讓你的application不用自己來管你是連向那一個db。 然後具體設定是由configuration來決定。 這樣子你才改得輕鬆的。 -------------------------- 另外,你說把Singleton以parameter來丟。 我想說:你真的要丟dbClass這個class嗎? 還是你是打算為了解決這種囧事,再去多做一個Factory,把不同的db包起來? ``` ![](https://i.imgur.com/c7Kg8Gg.png) ![](https://i.imgur.com/5jWava7.png) ![](https://i.imgur.com/yc5luJY.png) ![](https://i.imgur.com/gM5pcM8.png) [ref](https://zhuanlan.zhihu.com/p/23713957)