Skip to content. | Skip to navigation

Personal tools

Sections

Contrasting views on Protocols

Here are two slightly different viewpoints on the new protocol extension feature of Swift. Read and catch up below.

Sample quote from Metablog

"The simple fact is that actual Object Oriented Programming is Protocol Oriented Programming, where Protocol means a set of messages that an object understands. In a true and pure object oriented language like Smalltalk, it is all that can be, because the only way to interact with an object is to send messages. Even if you do simple metaprogramming like checking the class, you are still sending a message. Checking for object identity? Sending a message. Doing more intrusive metaprogramming like "directly" accessing instance variables? Message. Control structures like if and while? Message. Creating ranges? Message. Iterating? Message. Comparing object hierarchies? I think you get the drift.

So all interacting is via messages, and the set of messages is a protocol. What does that make OO? Say it together: Protocol Oriented Programming."

 

Alternative viewpoint from Mike Ash

"This is my favorite new Swift feature by far. Protocol extensions allow protocols to contain method implementations, not just method declarations. This is a feature I've wanted in Objective-C for ages, and I'm glad to see it show up even if it took a new language.

Previously, in both Objective-C and Swift, protocols contained only method declarations. They were pure interface definitions, just a list of things for conforming types to implement. With protocol extensions in Swift 2, protocols can now contain method implementations as well as declarations."

For me the big take away is the line "This is a feature I've wanted in Objective-C for ages" from Mike. My perspective is that we didn't need Swift to have protocol extensions. In fact as features get added to Swift some also get added to Objective-C. So then why Swift? 

I will leave that to another day.

Add comment

You can add a comment by filling out the form below. Plain text formatting. Comments are moderated.