Swift : Protocol Oriented Programming

Animesh Mishra
2 min readJun 10, 2018

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

In the POP, systems are designed by defining protocols. Three techniques are used in this design. They are :

  • protocol inheritance
  • protocol composition
  • protocol extensions

POP

  • Starts with the protocol
  • Conforms multiple protocols
  • Has the choice of using classes, structures, and enumerations
  • Uses a combination of protocols and protocol extensions to implement polymorphism
  • Uses protocol extensions to add functionality to types that conform to our protocols

1. Protocol Inheritance

  • A protocol can inherit the requirements from one or more other protocols.
  • It can add further requirements on top of the requirements it inherited.
  • Similar to class inheritance in OOP, however, instead of inheriting functionality, requirements are inherited.

The advantage of protocol inheritance over class inheritance is that the protocols can inherit the requirements from multiple protocols.

--

--