I am a iOS/swift newbie coming from the C# world. In C#, I've followed the principle of 'programming to an interface' whenever possible. Is that a pattern that people follow in the swift world? For instance if there is a CustomerService, do I start with a CustomerServiceProtocol that the CustomerService conforms to?
Asked
Active
Viewed 80 times
1
-
I don't really follow the _programming against interfaces_, why you mean? – Victor Sigler Sep 02 '15 at 21:57
-
As a simple answer, yes I have found that using protocols instead of explicit classes makes things a lot cleaner in Swift, and I am very much looking forward to being able to use protocol extensions in Swift 2. – Rupert Sep 02 '15 at 23:46
-
@VictorSigler I meant "program to an interface" http://stackoverflow.com/questions/383947/what-does-it-mean-to-program-to-an-interface – darthjit Sep 02 '15 at 23:56
1 Answers
4
I'm sure you are well aware of the principle that states, "prefer composition to inheritance." Protocols, and now especially with Swift 2's protocol extensions, are a great tool to create functionality via composition. The following blog post offers a great explanation and comparison to C#.

Mr Beardsley
- 3,743
- 22
- 28