Reference article
http://pengguo.xyz/tutorial/2017/03/15/Swift-World-Design-Patterns-Decorator.html
https://medium.com/design-patterns-in-swift/design-patterns-in-swift-decorator-pattern-2026e7112869
https://medium.com/jeremy-codes/decorator-pattern-in-swift-e5fa11ea3c3f
-
什么是装饰者模式
在面向对象的编程里,装饰者模式可以动态的添加behavior到object,而且不影响其他类。
Core component (Macbook)
Concrete Component (Macbook air)
Decorator (Macbook decorator)
Concrete Decorator(Macbook with touch bar) -
好处
处理类似的对象,复杂的结构。不至于子类过多 -
应用场景(Demo)
https://github.com/SamStone92/DesignPatternsInSwift
网友评论