【发布时间】:2015-12-26 15:22:36
【问题描述】:
在此 PDF 中的幻灯片 62:Some Columbia College Presentation 上,它说 Swift 及其扩展背后的想法之一是使用组合模式符合协议。
现在我了解了 Swift 中扩展的语法
//example from Apple:
extension SomeType: SomeProtocol, AnotherProtocol {
// implementations of not yet provided functions and properties of SomeType go here
}
但是构图模式与它有什么关系呢?这家伙确实是指here 描述的复合 模式,对吧?有人可以提供一个如何使用它的最小示例吗?
【问题讨论】:
-
示例中的“组合模式”意味着 SomeType 符合 SomeProtocol 和 AnotherProtocol 协议。不要在幕后寻找一些魔法或巫师......尝试检查苹果文档并尝试使用他们正在使用的术语。如何使用基于协议的编程模式写得很好。
标签: swift design-patterns protocols composition composite