我要正兒八經的弄懂設計模式。這是開始,先搞明白的什麼是設計模式。git
設計模式是一套被 反覆使用、多數人知曉、通過分類編目的、代碼設計經驗的總結。github
爲了 可重用 代碼,讓代碼更容易的被他人理解並保證代碼的 可靠性。設計模式
四人組( Gang of Four ),簡稱 GoF ,分別是 Erich Gamma, Richard Helm , Ralph Johnson 和 John Vlissides 。但不是他們設計的,是他們在 95年的時候整理概括 23 種最經常使用的設計模式並會變成一本書 Design Patterns: Elements of Reusable Object-Oriented Software 就是:《設計模式:可複用面向對象軟件的基礎》 。是通過時間的驗證的,你們必定要學會。框架
balabala ...
ide
設計模式最重要的 4 個元素 模式名稱 (Parttern Name)、 問題(Problem) 、 解決方案 (Solution) 、 效果 (Consequences)。
學習設計模式咱們就從這 4 個元素出發。一個一個弄清楚它。post
來個預覽先(參考)學習
類型ui |
模式名稱spa |
學習難度.net |
使用頻率 |
建立型模式 Creational Pattern |
單例模式 Singleton Pattern |
★☆☆☆☆ |
★★★★☆ |
簡單工廠模式 Simple Factory Pattern |
★★☆☆☆ |
★★★☆☆ |
|
工廠方法模式 Factory Method Pattern |
★★☆☆☆ |
★★★★★ |
|
抽象工廠模式 Abstract Factory Pattern |
★★★★☆ |
★★★★★ |
|
原型模式 Prototype Pattern |
★★★☆☆ |
★★★☆☆ |
|
建造者模式 Builder Pattern |
★★★★☆ |
★★☆☆☆ |
|
結構型模式 Structural Pattern |
適配器模式 Adapter Pattern |
★★☆☆☆ |
★★★★☆ |
橋接模式 Bridge Pattern |
★★★☆☆ |
★★★☆☆ |
|
組合模式 Composite Pattern |
★★★☆☆ |
★★★★☆ |
|
裝飾模式 Decorator Pattern |
★★★☆☆ |
★★★☆☆ |
|
外觀模式 Façade Pattern |
★☆☆☆☆ |
★★★★★ |
|
享元模式 Flyweight Pattern |
★★★★☆ |
★☆☆☆☆ |
|
代理模式 Proxy Pattern |
★★★☆☆ |
★★★★☆ |
|
行爲型模式 Behavioral Pattern |
職責鏈模式 Chain of Responsibility Pattern |
★★★☆☆ |
★★☆☆☆ |
命令模式 Command Pattern |
★★★☆☆ |
★★★★☆ |
|
解釋器模式 Interpreter Pattern |
★★★★★ |
★☆☆☆☆ |
|
迭代器模式 Iterator Pattern |
★★★☆☆ |
★★★★★ |
|
中介者模式 Mediator Pattern |
★★★☆☆ |
★★☆☆☆ |
|
備忘錄模式 Memento Pattern |
★★☆☆☆ |
★★☆☆☆ |
|
觀察者模式 Observer Pattern |
★★★☆☆ |
★★★★★ |
|
狀態模式 State Pattern |
★★★☆☆ |
★★★☆☆ |
|
策略模式 Strategy Pattern |
★☆☆☆☆ |
★★★★☆ |
|
模板方法模式 Template Method Pattern |
★★☆☆☆ |
★★★☆☆ |
|
訪問者模式 Visitor Pattern |
★★★★☆ |
★☆☆☆☆ |
看圖得知,這是按照用途分爲三種: 建立型(Creational, 結構型(Structural, 行爲型(Behavioral 三種。
接下來就按照表格 模式名稱這一列順序一一講解。學習難度和使用頻率並不重要,由於我都要會。
更新中:
1. 什麼是設計模式
2. 單例模式
3. 簡單工廠模式
這裏老是最新的
看完給個star鼓勵一下