# 設計模式—結構模式 ---- 設計模式的核心概念 ``` Your problem has been solved by someone. Patterns is not the reuse of code, is the reuse of experience. ``` ---- 軟體設計中的經典解決方案。 --- Intent(意圖) Motivation(動機) Structure(結構) Code example(實現) --- 結構模式-Structural Patterns --- - Creational patterns - Structural patterns - Behavioral patterns --- > Classification of patterns categorized by their intent. --- **Creational Patterns 創建型模式** 提供有靈活性和可重用性的創建 object 的機制 provide object creation mechanisms that increase flexibility and reuse of existing code. --- **Behavioral patterns 行為模式** 在乎 Object 間有效率的溝通及責任分配的模式 take care of effective communication and the assignment of responsibilities between objects. --- **Structural patterns 結構型模式** 解釋如何組裝較大的 Object/Classes 結構,並同時保持結構的彈性和高效 explain how to assemble objects and classes into larger structures, while keeping the structures flexible and efficient. --- 結構型模式(Structural patterns)包含: 適配器(Adapter)模式 橋(Bridge)模式 組合(Composite)模式 裝飾(Decorator)模式 門面(Facade)模式 享元 (Flyweight)模式 代理(Proxy)模式 --- ![](https://i.imgur.com/0nCpAHg.png) --- 適配器(Adapter)模式 使接口不兼容的对象能够相互合作 --- ![](https://i.imgur.com/rHJxmhm.png) --- 橋(Bridge)模式 將一個複雜的 Class 或 Object 拆分成抽象層和實現層,使他們可以分別被開發使用 --- ![](https://i.imgur.com/n8stA1p.png) --- 組合(Composite)模式 把 Object 組合成樹狀結構,並像使用獨立對象一樣使用它們 又稱对象树、Object Tree 使用組合模式的前提條件 應用的核心模式可以用樹狀結構表示。 --- ![](https://i.imgur.com/PBtMj1a.png) --- 裝飾(Decorator)模式 讓你可以透過把新的行為放進 wrapper objects 中來將原對象綁定新行為 --- ![](https://i.imgur.com/P4PEU0F.png) --- 門面(Facade)模式 為 Library 、框架等複雜的Class提供一個簡單的接口 亦稱外觀 --- ![](https://i.imgur.com/fhhOAvx.png) --- 享元(Flyweight)共享單元模式 透過共享多個Object的相同狀態來在有限的RAM中載入更多內容 亦稱缓存、Cache、Flyweight --- ![](https://i.imgur.com/Rsg3LIR.png) --- 代理(Proxy)模式 提供某個 Object 的代理,並允許在把請求交給該Object前或後,進行一些處理。 --- 結構型模式(Structural patterns)包含: 適配器(Adapter)模式 橋(Bridge)模式 組合(Composite)模式 裝飾(Decorator)模式 門面(Facade)模式 享元(Flyweight)模式 代理(Proxy)模式 ---- intent 和 patterns **Structural patterns 結構型模式** 提供組裝較大的 Object/Classes 結構的同時保有靈活性和高效的模式 explain how to assemble objects and classes into larger structures, while keeping the structures flexible and efficient. ---
{"metaMigratedAt":"2023-06-15T17:55:50.632Z","metaMigratedFrom":"Content","title":"設計模式—結構模式","breaks":true,"contributors":"[{\"id\":\"55656006-7069-4b3c-b452-8f557a1d2ca8\",\"add\":4755,\"del\":2587}]"}
    320 views
   Owned this note