1. Class Diagram

2. MVC

3. Strategy

This pattern is similar to the delegation pattern: both patterns rely on a protocol instead of concrete objects for increased flexibility. Consequently, any object that implements the strategy protocol can be used as a strategy at runtime.
Unlike delegation, the strategy pattern uses a family of objects.
Delegates are often fixed at runtime. For example, the dataSource and delegate for a UITableView can be set from Interface Builder, and it’s rare for these to change during runtime.
Strategies, however, are intended to be easily interchangeable at runtime.
策略比如游戲里面切換random模式和順序模式,或者根據(jù)ab會(huì)有不同的推薦策略這種,重點(diǎn)是切換/一組。但是delegate其實(shí)是固定的,比如View的delegate基本和某個(gè)對象綁死。
4. Builder

Use the builder pattern when you want to create a complex object using a series of steps. This pattern works especially well when a product requires multiple inputs.

The builder pattern is great for creating complex objects in a step-by-step fashion. It involves three objects: the director, product and builder.
The director accepts inputs and coordinates with the builder; the product is the complex object that’s created; and the builder takes step-by-step inputs and creates the product.
5. MVVM

- Models hold app data. They’re usually structs or simple classes.
- Views display visual elements and controls on the screen. They’re typically
subclasses of UIView. - View models transform model information into values that can be displayed on a
view. They’re usually classes, so they can be passed around as references.
View models are classes that take objects and transform them into different objects, which can be passed into the view controller and displayed on the view. They’re especially useful for converting computed properties such as Date or Decimal into a String or something else that actually can be shown in a UILabel or UIView.
盡量不要把很多view綁定一個(gè)vm,會(huì)比較混亂哦,拆分會(huì)好一點(diǎn)。
6. Factory
A factory is very useful when you have a group of related products, such as polymorphic subclasses or several objects that implement the same protocol.
這里其實(shí)和我們根據(jù)不同場景進(jìn)入不同的編輯頁很像,就是規(guī)定好protocol然后init不同的concrete class。
7. Adapter

8. State

莫名覺得其實(shí)狀態(tài)機(jī)和策略模式有一點(diǎn)像,但是策略不會(huì)像狀態(tài)變的這么頻繁。
9. Fly Weight

例如如果生成的 UIColor 的 rgba 一樣,就返回同一個(gè)對象,減少內(nèi)存損耗。但這個(gè)要求比較高,不能一個(gè)修改影響別的使用,所以需要不可變最好。字體加載也可以適用。
10. Mediator

感覺有點(diǎn)像消息總線~ 也有點(diǎn)多播的意思 0.0 主要也是為了解耦 peer 之間的依賴,就像我們曾經(jīng)處理的組件間依賴。
11. Command

The invoker stores and executes commands; the command encapsulates an action as an object; and the receiver is the object that's acted upon.
This pattern works best for actions that need to be stored and executed later. If you always intend to execute actions immediately, consider calling the methods directly on the receiver instead.
12. Chain-of- Responsibility

責(zé)任鏈其實(shí)就是 View 的響應(yīng)傳遞的設(shè)計(jì)模式哦~ 就是一個(gè)個(gè)去問所有handler是不是可以處理醬紫。
13. Coordinator

The concrete router knows how to present view controllers, but it doesn’t know exactly what is being presented or which view controller will be presented next. Instead, the coordinator tells the router which view controller to present.
Use this pattern to decouple view controllers from one another. The only component that knows about view controllers directly is the coordinator.

在 coordinator 里面可以調(diào)用其他 coordinator 來做跳轉(zhuǎn)哈,其實(shí) coordinator 主要就是負(fù)責(zé)跳轉(zhuǎn),然后 router 負(fù)責(zé) present 動(dòng)作醬紫。