What is Protocol Oriented Programming

As a programmer or developer I can say that , neither I m completely understand the structured programming or Procedural programming or now protocol programming.Only thing I know that solving a problem using most suitable way ( suitable way means low resource and best performance ).

Lets coming to the topic , what exactly protocol oriented programming , let’s see

Protocol Oriented Programming is a new approach for programming which you decorate your classes, structs or enums using protocols. Swift does not support multiple inheritance, therefore problem pops out when you want to add multiple abilities to your class.Protocol Oriented Programming lets you to add abilities to a class or struct or enum with protocols which supports multiple implementations.

 

I create a Protocol CAR below , Remember I created Protocol not CLASS

Then I created two more protocols Runable and Jumpable

Then I created abilities using our Protocol CAR,Runable,Jumpable

As you see the above we used struct using Protocol we defined.
But there is a issue occurred while implementing this canJump and canRun are two abilities are custom structs. We fixed this issue but in a different manner.

We fixed this by Protocol Extension

Let try some example with code

// So this extensibility made my code base more flexible. Consider, // I do not want maxDistance in Runnable but DoubleTruck.