Swift – the First POP Language

At WWDC 2015, Apple announced that Swift is the world’s first Protocol-Oriented Programming (POP) language.

So What’s POP?

Protocol-Oriented Programming is a new programming paradigm ushered in by Swift 2.0. In the Protocol-Oriented approach, we start designing our system by defining protocols. We rely on new concepts: protocol extensions, protocol inheritance, and protocol compositions.

The paradigm also changes how we view semantics. In Swift, value types are preferred over classes. However, object-oriented concepts don’t work well with structs and enums: a struct cannot inherit from another struct, neither can an enum inherit from another enum. So inheritance – one of the fundamental object-oriented concepts – cannot be applied to value types.

On the other hand, value types can inherit from protocols, even multiple protocols. Thus, with POP, value types have become first class citizens in Swift.

Start with a Protocol

When designing a software system, we try to identify the elements needed to satisfy the requirements of a given system. We then model the relationships between these elements. We can start with a superclass and model its relationships through inheritance. Or we can start with a protocol and model the relationship as a protocol implementation. Swift provides full support for both interpretations. However, Apple tells us:

“Don’t start with a class, start with a protocol.”

Table of Contents

Continue reading this article on hack.guides() by Pluralsight