A protocoldefines a blueprint of methods, properties, and other requirements that suit a particular task or piece of functionality.
The protocol can then be adopted by a class, structure, or enumeration to provide an actual implementation of those requirements. A
Any type that satisfies the requirements of a protocol is said to conform to that protocol.
In POP,
protocols play a central role in defining the capabilities of types (such as classes, structs, and enums).
Instead of relying heavily on inheritance (as in OOP), POP promotes the composition of small, reusable protocols.
This encourages a more modular and decoupled design.
Get iOS Dev’s stories in your inbox
Join Medium for free to get updates from this writer.
Key Features:
Protocol Extensions
Swift allows extending protocols to provide default method implementations. This means that types conforming to protocols can get default behavior without the need for explicit implementation.
Press enter or click to view image in full size
Protocol Compositions
Swift supports combining multiple protocols into a single requirement using protocol composition, which enables a type to conform to multiple protocols.